【问题标题】:Spring Cloud Config Server - empty array for refreshed keysSpring Cloud Config Server - 刷新键的空数组
【发布时间】:2021-03-06 11:52:18
【问题描述】:

我有一个弹簧云配置服务器,如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

我为配置仓库配置了一个 webhook。 我还有一个在本地运行的 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 []

Refreshed 键的数组为空 我尝试更改为旧版本的 Spring Boot/Cloud,以及更新的版本,但这不起作用。

我看到了与我的案例类似的问题,但没有一个有任何答案。

【问题讨论】:

    标签: java spring spring-boot maven spring-cloud-config


    【解决方案1】:

    问题出在客户端,缺少 spring cloud 配置以及 spring cloud 的依赖管理 将此依赖项添加到客户端代码中

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

    解决了这个问题。

    【讨论】:

      【解决方案2】:

      在您的application.yml 中,您已经定义了spring.cloud.config.server.git.search-paths 配置键。但是,从 spring 官方文档中查看this doc,关键似乎应该是 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}'
      

      【讨论】:

      • 我可以通过从客户端中的服务器调用“/actuator/refresh”手动获取属性,当 github 挂钩发送 POST 到“/monitor”时,我只是在客户端中看不到更新' 在服务器中
      猜你喜欢
      • 2019-03-20
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多