【发布时间】:2019-02-15 04:03:18
【问题描述】:
当我从我的属性存储库中更改一个值并重新启动 Spring Cloud Config Server 时,这些更改不会反映在它的使用者身上。
my-microservice/application.properties:
spring.application.name=my-service
spring.cloud.config.uri=http://localhost:8888
MyServiceController.java
@RestController
public class MyServiceController {
@Autowired
private Configuration configuration;
@GetMapping("/my-service")
public MyServiceBean retrieveMyServiceProperties() {
// show propertie's values
return new MyServiceBean(configuration.getPropertie1(), configuration.getPropertie2());
}
}
spring-cloud-config-server/application.properties
server.port=8888
spring.application.name=spring-cloud-config-server
spring.cloud.config.server.git.uri=file://path
Git 存储库
my-service.properties
my-service.propertie1=1
my-service.propertie2=2
当我向 localhost:8080/my-service 发送 GET 请求时,我得到的结果是:
{
"propertie1":1,
"propertie2":2
}
好的,没关系!
但是,如果我更改 my-service.properties 并重新启动我的 Spring Cloud Config Server,则所做的更改不会反映 MyServiceController。我确实需要重新启动 my-microservice 应用程序,以使更改生效。
这是正常行为吗?我的意思是,如果这是远程的,那么,它应该配置是否缓存。
【问题讨论】:
-
你不应该重启配置服务器,而是在客户端调用
/refreshactuator 端点 -
成功了!谢谢。
标签: java spring spring-boot spring-cloud spring-cloud-config