开发者社区 > 云原生 > 正文

sentinel nacos数据源错误

我引入最近的Jar包启动后报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds0-sentinel-nacos-datasource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.alibaba.sentinel.datasource.factorybean.NacosDataSourceFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:265) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1253) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1168) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.registerBean(SentinelDataSourceHandler.java:182) ~[spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.lambda$afterSingletonsInstantiated$0(SentinelDataSourceHandler.java:72) ~[spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at java.util.TreeMap.forEach(Unknown Source) ~[na:1.8.0_171] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.afterSingletonsInstantiated(SentinelDataSourceHandler.java:60) ~[spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at com.services.demo.ServiceDemoApplication.main(ServiceDemoApplication.java:12) ~[classes/:na] Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.alibaba.sentinel.datasource.factorybean.NacosDataSourceFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:686) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:583) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:568) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:248) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] ... 22 common frames omitted Caused by: java.lang.NoClassDefFoundError: com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_171] at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_171] at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_171] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:668) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_171] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171] ... 29 common frames omitted

pom.xml文件如下:

4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.3.RELEASE com.services.demo service-demo 0.0.1-SNAPSHOT war service-demo service demo

<java.version>1.8</java.version> <spring-cloud.version>Finchley.SR2</spring-cloud.version> <spring-boot-admin.version>2.1.4</spring-boot-admin.version> <spring-cloud-alibaba.version>0.9.0.RELEASE</spring-cloud-alibaba.version> <sentinel-datasource-nacos.version>1.5.2</sentinel-datasource-nacos.version>

org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-web

org.springframework.cloud spring-cloud-starter-alibaba-nacos-config ${spring-cloud-alibaba.version} org.springframework.cloud spring-cloud-starter-alibaba-nacos-discovery ${spring-cloud-alibaba.version}

org.springframework.boot spring-boot-starter-test test

de.codecentric spring-boot-admin-starter-client ${spring-boot-admin.version} org.springframework.boot spring-boot-starter-security org.springframework.cloud spring-cloud-starter-alibaba-sentinel ${spring-cloud-alibaba.version} com.alibaba.csp sentinel-datasource-nacos ${sentinel-datasource-nacos.version} test

org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import

org.springframework.boot spring-boot-maven-plugin

spring-milestones Spring Milestones https://repo.spring.io/milestone false

配置文件如下:

spring: cloud: nacos: config: namespace: 67747088-40f3-49b3-ab58-b08e7efc08f6 server-addr: localhost:8848 discovery: namespace: 67747088-40f3-49b3-ab58-b08e7efc08f6 server-addr: localhost:8848

sentinel:
  transport:
    port: 8719
    dashboard: localhost:8080
  datasource:
    ds0:
      nacos:
        server-addr: localhost:8848
        data-id: service-demo-flow-rules
        group-id: SENTINEL_GROUP
        data-type: json
        rule-type: flow
    ds1:
      nacos:
        server-addr: localhost:8848
        data-id: service-demo-degrade-rules
        group-id: SENTINEL_GROUP
        data-type: json
        rule-type: degrade

原提问者GitHub用户ShZhengqin

展开
收起
白夜行fighting 2023-06-11 10:38:37 181 0
1 条回答
写回答
取消 提交回答
  • 回答4.png

    这是测试范围。因此,您会得到一个NoClassDefFoundError。

    原回答者GitHub用户fangjian0423v

    2023-06-11 11:29:59
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
workshop专场-微服务专场-开发者动手实践营-微服务-使用Nacos进行服务的动态发现和流量调度 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载
Nacos 启航,发布第一个版本, 云原生时代助力用户微服务平台建设 立即下载