alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.3k stars 12.84k forks source link

ClassNotFoundException: com.alibaba.nacos.common.utils.StringUtils #7828

Closed myifeng closed 2 years ago

myifeng commented 2 years ago

Describe the bug java.lang.ClassNotFoundException: com.alibaba.nacos.common.utils.StringUtils error occurs when using nacos 2.0.4 and spring-cloud-starter-alibaba-nacos-config 2.2.7.RELEASE

image

2022-02-24 08:42:15.415 ERROR 505380 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.NoClassDefFoundError: com/alibaba/nacos/common/utils/StringUtils
    at com.alibaba.nacos.client.logging.AbstractNacosLogging.<clinit>(AbstractNacosLogging.java:41) ~[nacos-client-2.0.4.jar:na]
    at com.alibaba.nacos.client.logging.NacosLogging.<init>(NacosLogging.java:40) ~[nacos-client-2.0.4.jar:na]
    at com.alibaba.nacos.client.logging.NacosLogging.<init>(NacosLogging.java:29) ~[nacos-client-2.0.4.jar:na]
    at com.alibaba.nacos.client.logging.NacosLogging$NacosLoggingInstance.<clinit>(NacosLogging.java:53) ~[nacos-client-2.0.4.jar:na]
    at com.alibaba.nacos.client.logging.NacosLogging.getInstance(NacosLogging.java:57) ~[nacos-client-2.0.4.jar:na]
    at com.alibaba.cloud.nacos.logging.NacosLoggingListener.onApplicationEvent(NacosLoggingListener.java:46) ~[spring-cloud-starter-alibaba-nacos-config-2.2.7.RELEASE.jar:2.2.7.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66) ~[spring-boot-2.6.3.jar:2.6.3]
    at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_212]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338) [spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) [spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:164) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195) ~[spring-cloud-context-3.1.0.jar:3.1.0]
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114) ~[spring-cloud-context-3.1.0.jar:3.1.0]
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77) ~[spring-cloud-context-3.1.0.jar:3.1.0]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66) ~[spring-boot-2.6.3.jar:2.6.3]
    at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_212]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338) [spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) [spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) [spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) [spring-boot-2.6.3.jar:2.6.3]
    at com.package.Application.main(Application.java:14) [classes/:na]
Caused by: java.lang.ClassNotFoundException: com.alibaba.nacos.common.utils.StringUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_212]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_212]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_212]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_212]
    ... 37 common frames omitted

Expected behavior A clear and concise description of what you expected to happen.

Acutally behavior A clear and concise description of what you actually to happen.

How to Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

realJackSun commented 2 years ago

could you provide your application's pom.xml?

myifeng commented 2 years ago

This is a dependency related to SpringCloud, nacos, and alibaba, omitting other business dependencies.

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.6.3</version>
      <relativePath/>
</parent>

<properties>
    <alibaba-dependencies.version>2.2.7.RELEASE</alibaba-dependencies.version>
    <java.version>1.8</java.version>
    <spring-cloud.version>2021.0.0</spring-cloud.version>
    <spring-cloud-bootstrap.version>3.1.0</spring-cloud-bootstrap.version>
    <nacos.version>2.2.7.RELEASE</nacos.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
            <version>${spring-cloud-bootstrap.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${alibaba-dependencies.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>${nacos.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>${nacos.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId>
            <version>2.0.4</version>
        </dependency>

    </dependencies>
</dependencyManagement>
myifeng commented 2 years ago

Oh, My bad. I'm using the wrong nacos that I built myself ,after removing it it worked.

ytqiao3 commented 2 years ago

May I ask how you modified it? I use the same version and still have this error

qingjiu0718 commented 1 month ago
  <!-- 引入nacos-client:1.4.8解决问题-->
   <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        <exclusions>
            <exclusion>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.alibaba.nacos</groupId>
        <artifactId>nacos-client</artifactId>
        <version>1.4.8</version>
    </dependency>