Spring-cloud-sleuth: add EnableAspectJAutoProxy(proxyTargetClass = true) be default

Created on 5 Nov 2015  路  7Comments  路  Source: spring-cloud/spring-cloud-sleuth

I have a project using Spring Boot 1.3.0.M5 and Spring Cloud Consul 1.0.0.M2. If I include a dependency to 1.0.0.M2 of Spring Cloud Sleuth in my POM I get the following exception when the webapp starts:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'cloudBusConsulInboundFlow' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consulInboundChannelAdapter' defined in class path resource [org/springframework/cloud/consul/bus/ConsulBusAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: @Scheduled method 'getEvents' found on bean target class 'ConsulInboundChannelAdapter' but not found in any interface(s) for a dynamic proxy. Either pull the method up to a declared interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass to 'true'
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 18 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consulInboundChannelAdapter' defined in class path resource [org/springframework/cloud/consul/bus/ConsulBusAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: @Scheduled method 'getEvents' found on bean target class 'ConsulInboundChannelAdapter' but not found in any interface(s) for a dynamic proxy. Either pull the method up to a declared interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass to 'true'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration$$EnhancerBySpringCGLIB$$adbe3920.consulInboundChannelAdapter(<generated>)
    at org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration.cloudBusConsulInboundFlow(ConsulBusAutoConfiguration.java:82)
    at org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration$$EnhancerBySpringCGLIB$$adbe3920.CGLIB$cloudBusConsulInboundFlow$4(<generated>)
    at org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration$$EnhancerBySpringCGLIB$$adbe3920$$FastClassBySpringCGLIB$$5faff540.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
    at org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration$$EnhancerBySpringCGLIB$$adbe3920.cloudBusConsulInboundFlow(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 19 more
Caused by: java.lang.IllegalStateException: @Scheduled method 'getEvents' found on bean target class 'ConsulInboundChannelAdapter' but not found in any interface(s) for a dynamic proxy. Either pull the method up to a declared interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass to 'true'
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:284)
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor$1.doWith(ScheduledAnnotationBeanPostProcessor.java:245)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:504)
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:240)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 37 more

Any ideas why this happens?

enhancement

Most helpful comment

I managed to get it running by adding

@EnableAspectJAutoProxy(proxyTargetClass = true)

to my Application class. Not too sure why I need to do that

All 7 comments

I managed to get it running by adding

@EnableAspectJAutoProxy(proxyTargetClass = true)

to my Application class. Not too sure why I need to do that

Sleuth requires aop and uses it to instrument @Scheduled things.

@dsyer thoughts?

I don't see a way round that if you want to use @Scheduled methods that are not proxied by default. You can also use spring.aop.proxy-target-class=true (in config file).

Does this turn into a documentation issue then?

Don't know. Let's keep it open for discussion at least. I suppose we could consider the effects of s-c-sleuth setting spring.aop.proxy-target-class=true (the user might not care and would not be surprised by this kind of thing).

Was this page helpful?
0 / 5 - 0 ratings