使用 svn 作为存储库的 spring-cloud-config-server 的奇怪问题

问题描述 投票:0回答:2

我使用 spring-cloud-config-server 和 SVN 作为存储库。当我启动云配置服务器和客户端[微服务]时,配置值被正确拾取。

更改配置值和 SVN 提交后,我将触发刷新 POST 调用,URL:http://localhost:8080/actuator/refresh [8080 是客户端端口]。 SVN 中的更新值未刷新。

众所周知,config-server 在本地存储 SVN 数据。[在我的例子中,文件夹位置 - /tmp/config-repo-5393789580706388886] 这里奇怪的是,SVN 中提交的更改会在本地更新,一旦触发“刷新”REST 调用。但只是应用程序没有接受它。

Spring 启动版本 - 2.1.3.
云版本-格林威治发布。

配置服务器详细信息:

Maven 依赖:

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

<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>

application.yml:

spring:
  application:
    name: spring-cloud-config-server
  profiles:
    active: subversion
  cloud:
    config:
      server:
         svn:
           uri: https://svn.*****.com/repos/****/microservices
           username: #####
           password: #####
         default-label: source
server:
  port: 8888

config-client[微服务]详细信息: Maven 依赖:

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

application.yml:

spring:
  application:
    name: [client-app-name]
  cloud:
    config:
      uri: http://localhost:8888
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
  security:
   enabled: false
server:
  port: 8080

启动配置客户端微服务时,能够看到它正在通过配置服务器从预期的 SVN 位置获取值。

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}

在调用测试 REST 调用以从配置客户端获取配置值时,我从 SVN 获取该值。

在文件 [client-app-name].properties 中进行更改并提交到 SVN 后。在执行 REST 调用 http://localhost:8080/actuator/refresh 时,得到以下响应,这是预期的。

[]-bash-4.2$ curl -X POST http://localhost:9000/actuator/refresh
["config.client.version","configValue"]-bash-4.2$

同时,按照预期从日志中获取以下消息。

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}

对 config-client 的 REST 调用,以获取更新的配置,仅返回之前的配置值。

如果我重新启动客户端,它将获取更新后的最新配置。另外,SVN 更改会在本地更新[在我的例子中,文件夹位置 - /tmp/config-repo-5393789580706388886]

我真的无法找出我所犯的错误。任何解决此问题的意见都会非常有帮助。非常感谢。

spring-cloud spring-cloud-netflix spring-cloud-config
2个回答
0
投票

您是否为组件设置了

@RefreshScope
注释?

例如,

TestProperties
是具有configValue的
@ConfigurationProperites

@Bean
public TestComponent(TestProperties properties) {
    return new TestComponent(properties.getConfigValue());
}

如果您像上面的示例一样使用原始 configValue,则必须对其进行注释。


@Bean
public TestComponent(TestProperties properties) {
    return new TestComponent(properties);
}

如果您按原样使用属性,它将被刷新。


0
投票

我也尝试使用 SVN 创建配置服务器,但无法获取服务器文件,您能否提供您的代码库或 Github URL

© www.soinside.com 2019 - 2024. All rights reserved.