清平75 2021-09-27 16:52 采纳率: 25%
浏览 337
已结题

关于使用fegin开启对sentinel的支持,项目启动报错的问题

在我学习使用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的降级也是可以用的。

  • 写回答

2条回答 默认 最新

  • a1767028198 2021-09-27 17:23
    关注

    你这是有啥地方加了aop了嘛?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月6日
  • 已采纳回答 9月28日
  • 修改了问题 9月28日
  • 创建了问题 9月27日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号