When moving to from spring-boot 1.4.3 to spring-boot 1.5.1 I run into problems with TraceFeignClientAutoConfiguration.feignHystrixBuilder when using OKHttp as the Http client.
The root cause is that OkHttpClient is final and is tried to be wrapped by an aop proxy.
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class feign.okhttp.OkHttpClient]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
The relevant parts of the stack trace is
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignHystrixBuilder' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/client/feign/TraceFeignClientAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [feign.Feign$Builder]: Factory method 'feignHystrixBuilder' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignClient' defined in class path resource [org/springframework/cloud/netflix/feign/FeignAutoConfiguration$OkHttpFeignConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class feign.okhttp.OkHttpClient]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:220)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1018)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:345)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:118)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignContext.getInstance(TraceFeignContext.java:28)
at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.get(FeignClientFactoryBean.java:128)
at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.feign(FeignClientFactoryBean.java:89)
at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:156)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 58 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [feign.Feign$Builder]: Factory method 'feignHystrixBuilder' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignClient' defined in class path resource [org/springframework/cloud/netflix/feign/FeignAutoConfiguration$OkHttpFeignConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class feign.okhttp.OkHttpClient]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 75 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignClient' defined in class path resource [org/springframework/cloud/netflix/feign/FeignAutoConfiguration$OkHttpFeignConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class feign.okhttp.OkHttpClient]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:220)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1018)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:345)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClient.client(TraceFeignClient.java:62)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClient.<init>(TraceFeignClient.java:57)
at org.springframework.cloud.sleuth.instrument.web.client.feign.SleuthHystrixFeignBuilder.builder(SleuthHystrixFeignBuilder.java:37)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClientAutoConfiguration.feignHystrixBuilder(TraceFeignClientAutoConfiguration.java:57)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClientAutoConfiguration$$EnhancerBySpringCGLIB$$623eb257.CGLIB$feignHystrixBuilder$1(<generated>)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClientAutoConfiguration$$EnhancerBySpringCGLIB$$623eb257$$FastClassBySpringCGLIB$$613d7599.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClientAutoConfiguration$$EnhancerBySpringCGLIB$$623eb257.feignHystrixBuilder(<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:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 76 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class feign.okhttp.OkHttpClient]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:213)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:469)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:349)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
... 98 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class feign.okhttp.OkHttpClient
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:565)
at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at org.springframework.aop.framework.CglibAopProxy$ClassLoaderAwareUndeclaredThrowableStrategy.generate(CglibAopProxy.java:991)
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337)
at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:55)
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:203)
... 105 more
Disabling sleuth feign support solves the issue - but I would like to have sleuth support for the http interaction.
spring:
sleuth:
feign:
enabled: false
Which version of Sleuth are you using? Is it Camden?
It is Camden.SR5
Can you try setting spring.aop.proxyTargetClass: false and see if it still fails? Also you could upload a sample on github - it would be easier to work with for both of us I guess
Thanks for the hint - it still fails with spring.aop.proxyTargetClass: false - currently I am trying to reproduce the issue in a small sample project - but no success so far.
now I could reproduce the issue - adding zipkin-starter finally made it fail. Here is my project to reproduce the issue - https://github.com/mduesterhoeft/reproduce-spring-cloud-sleuth-513
Cool - thanks - I'll check it out asap.
@mduesterhoeft I have placed the
spring.aop.proxyTargetClass=false
in the application.properties and everything works fine. Please try again as a workaround.
@dsyer from what I understood from talking to the Boot guys currently the approach is such that Boot by default is intelligent enough to always use a class extension unless the class is final. I think we should remove the
map.put("spring.aop.proxyTargetClass", "true");
from the TraceEnvironmentPostProcessor. Actually we don't have any other option cause like this issue proves it there are cases where we have final classes that we can't subclass. Do you have any counter argument not to do this?
@marcingrzejszczak strange - spring.aop.proxyTargetClass=false solves it in the sample project but not in my real project 馃槙
maybe you're setting the value somewhere in a brute force manner? :P Or you have it on a class @EnableAspectJProxy(targetClass = true) or sth like that?
Had the same problem while upgrading to Spring Boot 1.5. Setting spring.aop.proxyTargetClass=false did it fix for me.
Thanks
I'll repost this cause maybe it got lost somehow
@dsyer from what I understood from talking to the Boot guys currently the approach is such that Boot by default is intelligent enough to always use a class extension unless the class is final. I think we should remove the
map.put("spring.aop.proxyTargetClass", "true");
from the TraceEnvironmentPostProcessor. Actually we don't have any other option cause like this issue proves it there are cases where we have final classes that we can't subclass. Do you have any counter argument not to do this?
Checked this out and if we turn it on then we start having problems when using Websockets
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientInboundChannel' defined in org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.messaging.support.AbstractSubscribableChannel]: Factory method 'clientInboundChannel' threw exception; nested exception is java.lang.IllegalStateException: @Bean method AbstractMessageBrokerConfiguration.clientInboundChannelExecutor called as a bean reference for type [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy84]. Overriding bean of same name declared in: org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
That's because we have aspects over Executors in TraceAsyncAspect. We'll have to do sth about this before going any further.
Added explicit support for Feign, Sleuth, OkHttpClient. I've checked your sample with Camden and Dalston and it worked fine.
Hi guys,
Just wanted to add that I've stumbled upon a similar issue with com.ibm.ws.concurrent.internal.ManagedExecutorServiceImpl.
It is an Executor's implementation from WebSphere Liberty profile. After adding spring-cloud-starter-sleuth:1.1.2 dependency during the startup Spring failed to proxy this class.
Setting spring.aop.proxyTargetClass=false resolved this issue.
WE can't unset this value unfortunately cause websockets will be broken. In general most cases work fine so for those special situations we'll need to set the spring.aop.proxyTargetClass=false
Hi,
I pretty much got same setup like @vitaliylevashin
Spring Boot 1.5.2
Spring Cloud Camden SR 6. (Spring Cloud Consul 1.1.3)
WebSphere Liberty 16.x
Developing services using Spring cloud. We are making use of Liberty's threading mechanism in some of service projects as shown below:

For debugging purposes, I'm trying to use Spring cloud Sleuth. On adding spring-cloud-starter-sleuth:1.1.3 to POM, server startup failed complaining about com.ibm.ws.concurrent.internal.ManagedExecutorServiceImpl.
So I added spring.aop.proxyTargetClass=false in application.properties. But that didn't help either. Still I'm getting following exception on server startup. I really appreciate your help.
