Implicit dependency between BeanNameAutoProxyCreator and imported
configuration
At my company, we're working on an aspect-oriented trace interceptor,
similar to DebugInterceptor. We're configuring a
CustomizableTraceInterceptor and using a BeanNameAutoProxyCreator to
auto-proxy beans for AOP.
The problem we're facing is that, when we introduce the
BeanNameAutoProxyCreator in the configuration:
@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;
}
}
We get a org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [X], where X is a Resteasy Proxy. This Resteasy
Proxy is declared in BConfig.
Now, if I move the Resteasy Proxy bean configuration up to AConfig, this
issue is solved, and @DependsOn solves the issue too.
My questions are 3: when is Spring able to resolve dependencies between
beans? Why using a BeanNameAutoProxyCreator changes this behavior? What is
the recommended way of solving this issue (BeanPostProcessor, @DependsOn,
etc.).
No comments:
Post a Comment