当前位置: 首页 > 知识库问答 >
问题:

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

印嘉泽
2023-03-14

我试图用spring Cloud Config和数据库后端设置一个Spring Boot项目。我在设置中有以下内容:

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;

我在DB中有一个条目。

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

为了刷新,我在/actuator/refresh中使用空主体执行一个POST操作,它返回成功200。但是message字段的值仍然是来自属性文件的值,并且没有更新。

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

共有1个答案

长孙宜
2023-03-14

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

在服务器端,我在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
management.endpoints.web.exposure.include=refresh
 类似资料:
  • 问题内容: 我已经安装了 Python 3.4.0 版, 并且希望使用MySQL数据库进行项目。我下载并尝试安装 MySQLdb ,但对于此版本的Python而言并不成功。有什么建议可以解决此问题并正确安装吗? 问题答案: MySQLdb不支持Python 3,但它不是唯一的Python MySQL驱动程序。 mysqlclient本质上是MySQLdb的一个分支,其中合并了Python 3支持(

  • 问题内容: 我正在尝试通过dropzone将图像文件的特定- 已经已知位置ID发送到后端,该ID将被上传到服务器上。尽管正在使用,但没有看到任何内容。相反,仅显示了此“ ”。 我希望在示例中看到fpos = 16; 问题答案: 不知道您的特定错误,但是这是一个简单的示例,说明如何使用jQuery使用dropzone发送其他数据并在后端使用php接收数据。 的HTML: js: 成功事件仅用于演示如

  • pom.xml已更新: spring.version=3.2.4.发布spring.security.version=3.1.4.发布 然后我添加了一个新的java配置类,而不是spring-security.xml null 有人能给出一个建议吗?

  • 主要内容:概述,一、业务场景介绍,二、Spring Cloud核心组件:Eureka,三、Spring Cloud核心组件:Feign,四、Spring Cloud核心组件:Ribbon,五、Spring Cloud核心组件:Hystrix,六、Spring Cloud核心组件:Zuul,七、总结:概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术。不过大多数讲解还停留在对Spring Cloud功能使用的层面,其底层的很多原理,很多人可能并不知晓

  • 不是为Spring Cloud Config Server提供一个AppRole或Static令牌来访问所有应用程序的所有机密,是否可以配置Spring Cloud Vault Config来在配置请求中使用给定的令牌? 这种通信将通过带有标头中的令牌的双向SSL进行。向外发送这样的令牌并不理想,但在这种情况下似乎是合适的解决方案。 请记住,这是一个Spring Cloud Config服务器,它