spring config

注册了如下的BeanPostProcessor

  1. AutowiredAnnotationBeanPostProcessor
    autowires annotated fields, setter methods and arbitrary config methods. Such members to be injected are detected through a Java 5 annotation: 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

  2. CommonAnnotationBeanPostProcessor
    This post-processor includes support for the PostConstruct and PreDestroy
    annotations
    The central element is the Resource annotation for annotation-driven injection of named beans
    JSR250注解(默认byName,与@Autowire的和@Inject相对)

  3. PersistenceAnnotationBeanPostProcessor
    BeanPostProcessor that processes PersistenceUnit and PersistenceContext annotations, for injection of the corresponding JPA resources EntityManagerFactory and EntityManager.

  4. RequiredAnnotationBeanPostProcessor
    BeanPostProcessor implementation that enforces required JavaBean properties to have been configured. Required bean properties are detected through a Java 5 annotation: by default, Spring's Required
    annotation.

可以看出,这些Annotation都是用在BeanDefinition已经注册,在实例化Bean时用的,如设置属性,初始化,销毁等。

componentScan是Annotation-config的超集,除了注册了以上的BeanPostProcessor以外,更主要的是它会扫描basePackage,然后根据注解注册BeanDefinition。
可以识别的注解包括了@Component, @Service, and @Controller, @Repository。
可以通过来进一步定制。
具体的工作由ComponentScanBeanDefinitionParser或者ComponentScanAnnotationParser来完成。

你可能感兴趣的:(spring config)