alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.41k stars 8.03k forks source link

NacosDataSource ClassNotFoundException when using Spring Cloud Alibaba #1222

Closed wangshiyang closed 4 years ago

wangshiyang commented 4 years ago
   Caused by: java.lang.NoClassDefFoundError: com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_201]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_201]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_201]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 24 common frames omitted
   Caused by: java.lang.ClassNotFoundException: com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_201]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_201]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_201]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_201]
... 28 common frames omitted

this is my pom.xml

     <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-dubbo</artifactId>
    </dependency>

com.alibaba.cloud version is: 2.1.1.RELEASE org.springframework.boot version is: 2.2.2.RELEASE org.springframework.cloud version is: Hoxton.RELEASE

and bootstrap.yml:

spring:
  application:
    name: sentinel-gateway
    sentinel:  
      transport:
        dashboard: 10.10.102.196:8080  
      datasource:
        ds:
          nacos:  
            server-addr: ${NACOS-HOST:nacos-register}:${NACOS-PORT:30000}
            dataId: ${spring.application.name}-sentinel
            groupId: DEFAULT_GROUP
            ruleType: degrade
    gateway:
      discovery:
        locator:  
          enabled: true
          lower-case-service-id: true

    nacos:  
      discovery:
        server-addr: ${NACOS-HOST:nacos-register}:${NACOS-PORT:30000}
      config:
        server-addr: ${spring.cloud.nacos.discovery.server-addr}
        file-extension: yml
        shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

server:
  port: 8002
sczyh30 commented 4 years ago

Could you print out your dependency tree and find whether sentinel-datasource-extension-nacos exists?

wangshiyang commented 4 years ago

Could you print out your dependency tree and find whether sentinel-datasource-extension-nacos exists?

No sentinel-datasource-extension-nacos dependency found. I'm used the official document configuration. Do I need to quote sentinel-datasource-extension-nacos separately?

sczyh30 commented 4 years ago

You'll need to introduce the datasource dependencies (e.g. sentinel-datasource-nacos) by yourself.