1
resposta

Erro ao subir o config-server

Estou tentando subir projeto config-server e recebo sempre o mesmo erro na console:


*Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
*org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nativeEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/NativeRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.config.server.environment.NativeEnvironmentRepository]: Factory method 'nativeEnvironmentRepository' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/config/ConfigDataEnvironmentUpdateListener
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.config.server.environment.NativeEnvironmentRepository]: Factory method 'nativeEnvironmentRepository' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/config/ConfigDataEnvironmentUpdateListener
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.2.jar:5.3.2]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.2.jar:5.3.2]
    ... 20 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/config/ConfigDataEnvironmentUpdateListener
    at org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryFactory.build(NativeEnvironmentRepositoryFactory.java:39) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at org.springframework.cloud.config.server.config.NativeRepositoryConfiguration.nativeEnvironmentRepository(EnvironmentRepositoryConfiguration.java:321) ~[spring-cloud-config-server-3.0.4.jar:3.0.4]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.2.jar:5.3.2]
    ... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.config.ConfigDataEnvironmentUpdateListener
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]

    Segue abaixo as configurações do meu projeto config-server:

    ===> POM.XML
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <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>
        </dependencies>

    </dependencyManagement>

===> ConfigServerApplication
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }

}

===> application.yml
server:
  port: 8888

spring:
  profiles:
    active: native
  cloud:
     config:
       server:
         native:
           search-locations: file:///home/claudio/WORKSPACE_ALURA_MICROSSERVICOS/microservice-repo
1 resposta

Olá Claudio, tudo bem?

Pelo erro apresentado na console, parece que está faltando a classe ConfigDataEnvironmentUpdateListener. Isso pode estar acontecendo porque a versão do Spring Cloud Config Server que você está utilizando (3.0.4) é incompatível com a versão do Spring Boot (2.4.1) que está no seu pom.xml.

Uma solução seria atualizar a versão do Spring Boot para uma compatível com a versão do Spring Cloud Config Server. Você pode verificar a versão compatível no site do Spring Cloud.

Outra possível solução seria adicionar a dependência do Spring Boot Config Data no seu pom.xml, já que a classe ConfigDataEnvironmentUpdateListener é parte dessa dependência.

Espero ter ajudado e bons estudos!