spring boot 获取 application.properties 中的值

参考:http://www.fengyunxiao.cn

1. application.properties 中添加值

myHeight=200
myInfo=myHeight:${myHeight}

2. controller中注入该值,并在方法中输出

@RestController
public class HelloController {

    @Value("${myHeight}")
    private Integer myHeight;
    @Value("${myInfo}")
    private String myInfo;

    @RequestMapping(value = "/getValue", method = RequestMethod.GET)
    public String hello() {
        return myInfo + ",height:"+myHeight;
    }
}

3. 打开浏览器访问

参考:http://www.fengyunxiao.cn

原文地址:https://www.cnblogs.com/zscc/p/9417882.html