not eligible for auto-proxying

not eligible for auto-proxying

<Bean 'customerService' of type [class com.xxx.CustomerServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)>

遇到这样一个问题,指定的Bean在容器加载时报了此警告,意思是不适合自动注入。导致的现象是bean里的属性依赖在使用时抛空指针异常。

上图是Spring源码里关于此段警告的判断。

应该是由于Bean的加载关系,导致依赖关系不能被Spring正常解决,才抛出了这个警告。

程序里Bean之间的依赖主要是使用注解来完成,后来查找代码,发现一个监听器引用了一个spring bean.而这个监听器又被比依赖注入更早的quartz引用。

 

A: private MailService mailService;
B: private MailSender mailSender;
C: private CustomerService customerService
D: private NotifyService notyfyService;
@autowire
A 引用 B
C 引用 A
D 引用 A    :    C的DAO属性不能正常注入
D 不引用A : C的DAO属性能够正常注入
这里的notyfyService 被QuartzTriggerListener使用autowire引用.从而导致其被引用的bean,报出了不适合自动注入的警告。

http://stackoverflow.com/questions/1201726/tracking-down-cause-of-springs-not-eligible-for-auto-proxying

留下回复