Spring uses annotations to register beans to containers

Source: Internet
Author: User

1.spring uses annotations to define beans, or to register assembly beans with annotations. Including registering into the IOC, assembly includes automatic injection of member variables.

1.spring will automatically scan the annotations of all classes, and when these annotations are scanned, spring will register the beans in the IOC container. The writing Bean method of the XML file is omitted.

2.spring will automatically scan these annotations, and spring will automatically scan those annotations.

After configuring <CONTEXT:COMPONENT-SACN base-package= "xxxx" >, spring will automatically scan for annotations. Scans all content under the specified package.

If you set a conditional scan, you can use the filter again under Basepackage.

3.spring is started by using the Web. XML configuration to boot.

4. How do I use annotations to define a bean?

Annotations also have attributes, including the Name property. You can specify the name specified in the IOC container to which this bean is registered.

A singleton of 5.bean refers to a single case in an IOC container. If two different IOC containers, then there are two beans. You can specify a bean's build strategy, such as specifying that it is not a singleton, and specifying that there is a bean instance in each thread, you can override the implementation of scope, which actually has an interface that implements its own scope policy and can specify the different life cycles of the bean.

The life cycle of 6.bean refers to scope, including prototype,singleton,request

7.autuWire annotations, which can be used on member variables for automatic injection of member variables.

You can also use the method to complete the automatic injection of the method parameters.

8.autoWired annotations, which have the required attribute. Spring throws an exception if the bean is not found when it is automatically injected into the bean. You can set the required annotation with its property set to false, that is, the bean is non-mandatory, and no exception is thrown when the bean is not found.

Spring uses annotations to register beans to containers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.