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