spring怎样重新加载配置文件
在Spring中,可使用@RefreshScope
注解来实现重新加载配置文件。
@RefreshScope
注解,例如:@RefreshScope
@Component
public class MyBean {
// ...
}
application.properties
或application.yml
中添加以下配置:management.endpoints.web.exposure.include=refresh
确保Spring Boot利用中已配置了Spring Cloud Config Server或其他配置中心。
发送POST要求到/actuator/refresh
端点来触发配置文件的重新加载。可使用cURL或其他HTTP客户端工具发送要求。例如,使用curl发送要求:
$ curl -X POST http://localhost:8080/actuator/refresh
@RefreshScope
注解标记的类中的属性值。TOP