1.在使用到@value('param')的类中添加@RefreshScope
@RestController
@RefreshScope
public class HelloController {
private Logger log = LoggerFactory.getLogger(HelloController.class);
@Value("${test.name}")
private String name;
@RequestMapping(value="/getName", method = RequestMethod.GET)
public String hello() {
log.info("call getName parameter:{}");
return "{hello: '" + name + "'}";
}
/**
* rest 服务用来测试
* --@requestParam url?xxx=name
* --requestBody 认定为json传输解析 url?{xxx=name}
* @param name
* @return
*/
@RequestMapping(value = "/hello", method = RequestMethod.POST)
public String hello(String name) {
log.info("call hello parameter:{}", name);
return "{hello: '" + name + "'}";
}
}
2.在pom.xml文件中添加spring-boot-starter-actuator
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
3.在当前应用中经过post的方式refersh
测试 postman http://localhost:8080/refresh
spring会刷新做用域