Spring Cloud Config Server-새로 고침 된 키에 대한 빈 배열

Nov 23 2020

나는이 같이 스프링 클라우드 설정 서버가 REPO 그리고이의 클라이언트 의 repo 다음은 내 POM 파일입니다

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ali.wassouf.spring.cloud.client</groupId>
    <artifactId>cloud-config-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cloud-config-app</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-monitor</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

구성 서버의 application.yml

server:
  port: 8081
spring:
  application:
    name: cloud-config-server
  cloud:
    config:
      server:
        monitor:
          github:
            enabled: true
          gitee:
            enabled: true
        git:
          password: ${PASSWORD}
          username: ${USERNAME}
          uri: https://github.com/Ali-Wassouf/springcloudconfigrepo
          search-paths: '{application}'

이 서버가 제공하는 구성 저장소의 구조는 다음과 같습니다.

.
+-- serviceA
|   +-- application-dev.properties
|   +-- application-prod.properties
+-- serviceB
|   +-- application-dev.properties
|   +-- application-prod.properties

구성 저장소에 대해 구성된 웹훅이 있습니다. 로컬에서 실행되는 rabbitMQ 이미지도 있습니다.

변경 사항을 구성 저장소에 푸시하면 콘솔에 다음 줄이 표시됩니다.

o.s.c.c.monitor.PropertyPathEndpoint     : Refresh for: *:prod
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2c943d8f: startup date [Mon Nov 23 18:55:19 CET 2020]; root of context hierarchy
o.s.core.annotation.AnnotationUtils      : Failed to introspect annotations on [class org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration$RetryConfiguration]: java.lang.IllegalStateException: Could not obtain annotation attribute value for public abstract java.lang.Class[] org.springframework.boot.autoconfigure.condition.ConditionalOnClass.value()
trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$aacb9e64] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7d2d9a8f: startup date [Mon Nov 23 18:55:20 CET 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2c943d8f
o.s.boot.SpringApplication               : Started application in 1.515 seconds (JVM running for 31.102)
s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7d2d9a8f: startup date [Mon Nov 23 18:55:20 CET 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2c943d8f
s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2c943d8f: startup date [Mon Nov 23 18:55:19 CET 2020]; root of context hierarchy
o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []

새로 고침 된 키 배열이 비어 있습니다. 이전 버전의 Spring Boot / Cloud와 최신 버전으로 변경하려고했지만 작동하지 않았습니다.

나는 내 사건과 유사한 질문을 보았지만 그들 중 누구도 대답이 없었습니다.

답변

jalsh Nov 24 2020 at 06:47

당신에 application.yml당신이 정의한 spring.cloud.config.server.git.search-paths구성 키를. 그러나 봄 공식 문서 에서이 문서 를 살펴보면 핵심은 searchPaths(snakeCase, 대시 없음) 이어야합니다 . 따라서 application.yml다음과 같이 보일 것입니다.

server:
  port: 8081
spring:
  application:
    name: cloud-config-server
  cloud:
    config:
      server:
        monitor:
          github:
            enabled: true
          gitee:
            enabled: true
        git:
          password: ${PASSWORD} username: ${USERNAME}
          uri: https://github.com/Ali-Wassouf/springcloudconfigrepo
          searchPaths: '{application}'
Ali.Wassouf Nov 24 2020 at 09:39

문제는 클라이언트에 있었고, 스프링 클라우드 구성과 스프링 클라우드에 대한 종속성 관리가 누락되어이 종속성을 클라이언트 코드에 추가했습니다.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</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>

문제를 해결했습니다.