spring-cloud-sleuth: BeanCreationException with Feign and OKHttp (spring-boot 1.5.1)
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (10 by maintainers)
Added explicit support for Feign, Sleuth, OkHttpClient. I’ve checked your sample with Camden and Dalston and it worked fine.
@mduesterhoeft I have placed the
spring.aop.proxyTargetClass=false
in the
application.properties
and everything works fine. Please try again as a workaround.Cool - thanks - I’ll check it out asap.