在我学习使用fegin和sentinel时,我使用了fegin的远程调用,也在controller层加了sentinel服务熔断和限流,但是我发现当我开启配置
feign:
sentinel:
enabled: true # 激活Sentinel对Feign的支持
时项目就会启动报错:
2021-09-27 16:42:01.150 ERROR 12320 --- [ restartedMain] o.s.b.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'imageController': Unsatisfied dependency expressed through field 'pImgservice'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'PImageImpl': Unsatisfied dependency expressed through field 'redisCacheFeign'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bbs.common.feign.RedisCacheFeign': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignTargeter' defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration$HystrixFeignTargeterConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class org.springframework.cloud.openfeign.HystrixTargeter: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->class org.springframework.cloud.openfeign.HystrixTargeter$$EnhancerBySpringCGLIB$$4177c53a cannot access its superclass org.springframework.cloud.openfeign.HystrixTargeter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
......
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'PImageImpl': Unsatisfied dependency expressed through field 'redisCacheFeign'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bbs.common.feign.RedisCacheFeign': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignTargeter' defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration$HystrixFeignTargeterConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class org.springframework.cloud.openfeign.HystrixTargeter: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->class org.springframework.cloud.openfeign.HystrixTargeter$$EnhancerBySpringCGLIB$$4177c53a cannot access its superclass org.springframework.cloud.openfeign.HystrixTargeter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
.....
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
... 25 more
......
而当我去除那段配置时发现项目正常运行。我的配置写在openfegin的客户端中。sentinel的熔断也写在这里。请问有解决方法嘛?
经过我测试发现项目中没有使用Sentinel的降级和AOP,只是引入Sentinel的pom依赖,在开启了fegin对Sentinel的支持配置后,也会报相同的错误,这个配置主要是干嘛的?在不使用的时候,fegin的降级也是可以用的。