Original: http://www.cnblogs.com/digdeep/p/4525567.html
Spring's bean container-related annotations:1) @Autowired is the most used annotation, in fact it is autowire=Bytype is based on the type of automatic injection dependency (annotation-based dependency injection), which can be used on domain, method, and constructor functions.2) @Qualifier is autowire=byname, @Autowired annotation to judge multiple bean types, you need to use @Qualifier ("Xxbean") to specify the ID of the dependent bean: @Controller @requestmapping ("/USER") Public classHellocontroller {@Autowired @Qualifier ("UserService") PrivateUserService UserService;3@Resource belong to the JSR250 standard for attribute domain amounts and methods. is also a byname type of dependency injection. Usage: @Resource (name= "Xxbean"). @Resource default class name with no parameters The first letter is lowercase. Equivalent to: @Autowired @Qualifier ("Xxbean")4) JSR-330 Standard javax.inject.*notes in (@Inject, @Named, @Qualifier, @Provider, @Scope, @Singleton). @Inject is equivalent to @autowired, @Named is equivalent to @Qualifier, and the other @ Named also has @Component function on the class.5@Component, @Controller, @Service, @Repository, these annotations are different from the annotations above, and the annotations above are injected into the dependent bean, and these annotations are used to produce beans, These annotations are annotations on the class, annotating the class into a spring bean factory in one of the [email protected], @Service, @Repository is basically a more granular @component semantics.6@PostConstruct and @PreDestroy are not for dependency injection, but for the bean's life cycle. Similar to init-method (Initializeingbean) destory-method (Disposablebean)4In spring, the processing of annotations in spring is basically done by implementing interface Beanpostprocessor: Public InterfaceBeanpostprocessor {Object Postprocessbeforeinitialization (object bean, String beanname)throwsbeansexception; Object Postprocessafterinitialization (Object bean, String beanname)throwsbeansexception;} The related processing classes are: Autowiredannotationbeanpostprocessor, Commonannotationbeanpostprocessor, Persistenceannotationbeanpostprocessor, requiredannotationbeanpostprocessor These processing classes, can be<context:annotation-config/>Configure the implicit configuration into the spring container. These are the processing of dependency injections, as well as the processing of production bean annotations (@Component, @Controller, @Service, @Repository):<context:component-scan base- Package= "Net.aazj.service,net.aazj.aop"/>these are done by specifying the scan's base package path and scanning them into the spring bean container. Note Context:component-Scan will also default to Autowiredannotationbeanpostprocessor, Commonannotationbeanpostprocessor configuration in. So<context:annotation-config/> can be omitted. In addition context:component-Scan also scans for @aspect-style AOP annotations, but it needs to be included in the configuration file<aop:aspectj-autoproxy/> to cooperate.
Spring annotation 02