With spring annotations, you need to configure the component scanner in the configuration file to scan the annotations in the specified package
<base-package= "xxx.xxx.xxx.xxx"/>
1. Define Bean @Component
You need to use annotation @component on the class, and the VLAN attribute of the annotation is used to specify the value of the ID of the annotation.
Spring also provides three functional basic and @component equivalent annotations
@Repository used to annotate DAO implementation classes
@Service used to annotate Service implementation classes
@Controller used to annotate a Controller implementation class
[Email protected] scope @scope
You need to use the annotations @scope,vlan property on the class to specify the scope, which defaults to Singleton
3. Basic type Attribute Injection @value
You need to use host @value on the property, and the Value property of the annotation is used to specify the values to be injected
The non-setter method in the class when the attribute injection is completed using the modified annotation
4. Inject domain properties by type @autowired
You need to use annotation @autowired on domain properties, which by default uses automatic assembly of beans by type
When using this annotation to complete property injection, no setter method is required
5. Inject domain attributes by name @autowired and @qualifier
You need to use annotations @autowired and @qualifier on the domain properties. The @qualifier VLAN attribute is used to specify the ID value to match, and the object setter method
6. Domain attribute Annotations @resource
Spring provides support for defining @resource standard annotations in the JSR-250 specification.
@Resource annotations and the beans can be matched by name, or by type. By default, matches by type and then by name. If the value of the VLAN attribute is configured, only match by name
The life of the 7.Bean @postconstruct domain @predestroy
Spring Learning Note Four: Spring Common annotations Summary