在我的公司,我們正在研究面向方面的跟蹤攔截器,類似於DebugInterceptor
。我們正在配置一個CustomizableTraceInterceptor
並使用BeanNameAutoProxyCreator
爲AOP自動代理bean。BeanNameAutoProxyCreator和導入配置之間的隱式依賴關係
我們面臨的問題是,當我們在配置介紹BeanNameAutoProxyCreator
:
@Configuration @Import(BConfig.class) @EnableAspectJAutoProxy public class AConfig { @Bean public static BeanNameAutoProxyCreator beanNameAutoProxyCreator() { BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator(); beanNameAutoProxyCreator.setInterceptorNames(new String[] {DEBUG_INTERCEPTOR_NAME}); beanNameAutoProxyCreator.setBeanNames(new String[] {BEANS_NAMES_EXPRESSION}); return beanNameAutoProxyCreator; } }
我們得到一個org.springframework.beans.factory.NoSuchBeanDefinitionException:無型的排位豆[X] ,其中X是Resteasy代理。此Resteasy代理在BConfig
中聲明。
現在,如果我將Resteasy Proxy Bean配置移至AConfig,此問題就解決了,@DependsOn
也解決了這個問題。
我的問題是3:何時Spring能夠解決bean之間的依賴關係?爲什麼使用BeanNameAutoProxyCreator改變這種行爲?什麼是解決這個問題的推薦方法(BeanPostProcessor,@DependsOn等)。