Notes for Spring
Annotations on classes (annotations to the spring container are given by JavaBean)
If the annotations have no parameters, the default is the class name, if any. The bean's name is the parameter value
- @component The most primitive annotations will be javabean to the spring container
- @service give the Service (business) layer class to the Spring container management
- @repository give the DAO layer class to the Spring container management
- @controller give the class of the control layer to the Spring container management
Annotations on properties (annotations that assign values (initialization) to properties in a class)
- @value ("") is required for the base data type (including string) assignment parameter
- @AutoWrited [("parameter")] is the reference data assignment, the spring container will find the corresponding type, if the container has more than one type of value, need to pass parameters, spring container According to the name of the parameter to find the corresponding instance object, you can also use @quailfier ("") Annotation parameters Specify JavaBean
- @Resource [(name=" ")] assigns a value to the reference data, and if spring is a collection data type, it needs to be used with the <util> property.
① if both name and type are specified, The only matching bean from the spring context is found to be assembled, and an exception is thrown if it is not found.
② if name is specified, The matching bean that looks for the name (ID) from the context is assembled, and an exception is thrown if it is not found.
③ if type is specified, A unique bean similar to a match is found in the context, and an exception is thrown if it is not found or multiple.
④ If neither name is specified, If no type is specified, it is automatically assembled according to ByName, and if there is no match, the fallback is a match for the original type and is automatically assembled if matched.
- @Bean use XP with @configeuration for adding factory methods to spring containers:
Public person Getperson (return new person)
Equivalent to configuring <bean id= "Getperson" class= com.xxx "in Bean.xml. Person "/>
other Annotations
- @scope ("") specifies the scope for the bean: Request,session,singleton,prototype
- @PostConstruct function on the method, specify the initialization method for the bean
- @Perdestroy function on the method, specifying the method of destruction for the bean, only effective at Scope=singleton
Notes for Spring