1.問題描述
在配置spring cloud config 動態(tài)刷新時,POST訪問 /actuator/refresh刷新修改后的配置文件報404錯誤,報錯信息如下:

2.解決辦法
actuator的配置信息中management.endpoints.web.exposure.include="*"這行配置需要修改為management.endpoints.web.exposure.include=*,即去掉雙引號,如果您的這一行配置類似management.endpoints.web.exposure.include=["health","info","refresh"],那么需要修改為management.endpoints.web.exposure.include=refresh,info,health,修改后,如果沒有對配置文件做修改,那么訪問的結(jié)果就是如下:

如果修改了配置文件,那么訪問的結(jié)果就會是另一種情況,配圖如下:

上圖中的
from是配置文件被修改的屬性
需要注意的細節(jié)點:
1.配置actuator后,需要配置management.endpoints.enabled-by-default=true開啟actuator;
2.actuator的默認根路徑是/actuator,而不是/;
3.actuator的配置需要和端口的配置在同一個文件,例如:actuator的配置在bootstrap.properties文件,那么server.port也需要寫在bootstrap.properties文件,當(dāng)然,actuator的配置信息也可以寫在application.properties文件中;
4.@RefreshScope注解的添加
3.客戶端config-client主要代碼展示
- bootstrap.properties文件
#對應(yīng)前配置文件中的{application}部分
spring.application.name=didispace
#方式一:通過服務(wù)名訪問服務(wù)器
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=config-server
#方式二:配置中文件的地址 通過uri訪問配置服務(wù)
#spring.cloud.config.uri=http://localhost:5555/
#對應(yīng)前配置文件中的{profile}部分
spring.cloud.config.profile=dev
#對應(yīng)前配置文件的git分支
spring.cloud.config.label=feature-xiongzelin
eureka.client.service-url.defaultZone=http://localhost:1111/eureka/
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
eureka.instance.prefer-ip-address=true
server.port=8866
#actuator配置
management.endpoints.enabled-by-default=true
management.endpoint.health.show-details=always
#management.endpoints.web.exposure.include=refresh,info,health
management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/actuator
application.properties文件啥都沒有,就不需要要展示了
- 啟動類
···
@EnableEurekaClient
@SpringBootApplication
public class SpringCloudConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
}
}
- web控制器
···
@RefreshScope
@RestController
public class TestController {
@Value("${from}")
private String from;
@RequestMapping("/from")
public String from (){
return this.from;
}
}
4.代碼地址
碼云: