带有数据库后端的Spring云配置



我正在尝试使用数据库后端的spring Cloud Config来设置一个spring启动项目。我的设置中有以下内容:

application.properties
spring.application.name=my-services-api
spring.datasource.url=jdbc:h2:~/test
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.platform=h2
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.hikari.connection-timeout=5000
spring.datasource.hikari.maximum-pool-size=10
spring.profiles.active=jdbc
spring.cloud.config.uri=http://localhost:8080
spring.cloud.config.server.default-profile=production
spring.cloud.config.server.default-label=latest
spring.cloud.config.server.jdbc.sql=SELECT key, value FROM my_properties WHERE application=? AND profile=? AND label=?;
spring.cloud.config.server.jdbc.order=1

spring.h2.console.enabled=true
management.endpoints.web.exposure.include=refresh
message=default message

我在应用程序类中有@EnableConfigServer。此外,我在一个控制器中有@RefreshScope,我正试图从数据库中注入一个值。

@Value("${message}")
private String message;

我在数据库中有一个条目。

APPLICATION     |PROFILE    |LABEL      |KEY        |VALUE  
my-services-api |production |latest     |message    |Some New Hello

为了刷新,我在/actuator/refresh中用空正文进行POST,返回成功200。但message字段的值仍然是来自属性文件的值,并且没有更新。

当我执行GET/my-services-api/production/latest时,我会在响应中看到新值,但message字段仍然没有刷新。我是否缺少任何配置?谢谢

我不得不更改配置,以拥有一个单独的服务器和客户端:

在服务器端,我在application.properties:中有这个

spring.application.name=my-services-api
spring.datasource.url=jdbc:h2:~/test
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.platform=h2
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.hikari.connection-timeout=5000
spring.datasource.hikari.maximum-pool-size=10
spring.profiles.active=jdbc
spring.cloud.config.uri=http://localhost:8080
spring.cloud.config.server.default-profile=jdbc
spring.cloud.config.server.default-label=latest
spring.cloud.config.server.jdbc.sql=SELECT key, value FROM my_properties WHERE application=? AND profile=? AND label=?;
spring.cloud.config.server.jdbc.order=1

spring.h2.console.enabled=true
management.endpoints.web.exposure.include=refresh

logging.level.org.springframework.jdbc.core=TRACE

在客户端,我有一个bootstrap.properties,其中包含:

spring.application.name=my-services-api
spring.cloud.config.uri=http://localhost:8080
spring.cloud.config.label=latest
spring.cloud.config.profile=jdbc

和application.properties带有:

management.endpoints.web.exposure.include=refresh

为了刷新,我对客户端服务上的/executor/refresh进行了POST调用。

最新更新