demo:
username: xxx
@Value引用配置
注意使用 @Value 对应类必须声明成 @RefreshScope 可刷新
@RefreshScope
@RestController
@RequestMapping(“/demo”)
public class DemoController {
// 应用配置文件
@Value(“${demo.username}”)
private String username;
@GetMapping
public String demo() {
return username;
}
}
@Configuration 配置类使用
配置类声明成 @RefreshScope
@RefreshScope
@ConfigurationProperties(“demo”)
public class Demo implements InitializingBean {
private String username;
}
@RestController
@RequestMapping(“/demo”)
public class DemoController {
@Autowired
private Demo demo;
@GetMapping
public String demo() {
return demo.getUsername();
}
}
文档更新时间: 2021-08-10 17:00 作者:admin