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

posted @ 2018-08-04 10:58  亦寒2017  阅读(455)  评论(1编辑  收藏  举报