I read that Spring annotations like @Autowired
, @Transactional
& @PostConstruct
are a form of / use BeanPostProcessors.
Neither, it's actually the opposite. It is BeanPostProcessors that look for the annotations and react accordingly.
AutowiredAnnotationBeanPostProcessor
- BeanPostProcessor
implementation that autowires annotated fields, setter methods, and arbitrary config methods. Such members to be injected are detected through annotations: by default, Spring's @Autowired
and @Value
annotations.
Also supports JSR-330's @Inject
annotation, if available, as a direct alternative to Spring's own @Autowired
.
CommonAnnotationBeanPostProcessor
- BeanPostProcessor
implementation that supports common Java annotations out of the box, in particular the JSR-250 annotations in the javax.annotation
package. These common Java annotations are supported in many Java EE 5 technologies (e.g. JSF 1.2), as well as in Java 6's JAX-WS.
This post-processor includes support for the PostConstruct
and PreDestroy
annotations - as init annotation and destroy annotation, respectively - through inheriting from InitDestroyAnnotationBeanPostProcessor
with pre-configured annotation types.
Note that @Transactional
is not handled by a BeanPostProcessor
.
Now annotations like @Component
or @Bean
specify to Spring that it should create beans of this type. [...] So does that make @Component
and @Bean
BeanPostProcessors?
No.
@Component
is an annotation that the component-scanning framework looks for to find beans to register. The component-scanning framework also looks for annotations that are themselves annotated with @Component
, such as the @Configuration
, @Controller
, @Service
, and @Repositiory
annotations.
The @Bean
annotation is then handled by a BeanDefinitionRegistryPostProcessor
(not a BeanPostProcessor
).
ConfigurationClassPostProcessor
- BeanFactoryPostProcessor
used for bootstrapping processing of @Configuration
classes.
This post processor is priority-ordered as it is important that any Bean
methods declared in @Configuration
classes have their corresponding bean definitions registered before any other BeanFactoryPostProcessor
executes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…