Several ways in which spring's bean configuration

Source: Internet
Author: User

Method One: XML-based bean definitions (private attributes need to provide setter methods)

Method Two: annotation-based bean definition

Spring provides four annotations for this purpose, which is consistent with the XML definition bean effect above, by handing the component to the Spring container management. The name of the component defaults to the class name (lowercase), or you can modify it yourself: @Component: Use this annotation when the hierarchy of components is difficult to locate @Controller: Component @Service representing the control layer: component representing the business logic layer @ Repository: Represents a component of the data access layer when using these annotations there is one more place to note, which is the need to declare <contex:component-scan...> an item in the Applicationcontext.xml,  Indicates the package directory of the Spring container scan component. Method Three: Java class-based bean definition 1, first, requires a small amount of configuration in the XML to start the Java configuration, such as starting Component-scan 2, defining a configuration class annotated with @configuration the class, equivalent to the configuration in XML beans ; Using the @bean notation method is equivalent to configuring the Bean in XML

Several ways in which spring's bean configuration

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.