configServer提交後手動刷新

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會刷新做用域
相關文章
相關標籤/搜索