我引入最近的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} testorg.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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。