而不是每次我做任何更改时重新启动服务器,我希望我的属性文件自动刷新。我的属性文件在src / main / resources中
您可以使用Actuator,基本上您将配置bean放在刷新范围内:
@SpringBootApplication
public class ExampleServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleServiceApplication.class, args);
}
@RestController
@RefreshScope
class ExampleController {
@Value("${foo.bar}")
private String value;
@RequestMapping
public String sayValue() {
return value;
}
}
}
然后当您更改配置时。您可以调用执行器的刷新端点。
curl -X POST http://localhost:8080/refresh