CommonAnnotationBeanPostProcessor处理@Resource与@PostConstruct的范围
进阶版来源:tencent中级工程师ApplicationContext生命周期JSR-330标准注解@Inject与@Autowired注解CommonAnnotationBeanPostProcessor
答案解析
CommonAnnotationBeanPostProcessor 是 Spring 里用来支持 JSR 250 通用注解的 BeanPostProcessor,主要处理 @Resource、@PostConstruct、@PreDestroy 这几类注解。
对于 @Resource,它主要做依赖注入,作用范围一般是字段和 setter 方法。Spring 在 bean 实例化之后、初始化之前,会扫描 bean 类里的 @Resource 注解,然后解析要注入的依赖。
@Resource 默认是按名称注入,比如:
这里默认会找名字叫 userService 的 bean。如果显式指定 name:
那就按 orderService 这个 beanName 去找。找不到时,Spring 可能
登录后查看完整内容
