第十四章 springboot + profile(不同环境读取不同配置)

时间:2016-05-07 22:11:20   收藏:0   阅读:1642

具体做法:

技术分享

1、application-dev.properties(dev环境下的配置)

技术分享
1 profile = dev_envrimont
View Code

2、application-prod.properties(prod环境下的配置)

技术分享
1 profile = prod_envrimont
View Code

3、application.properties

技术分享
1 spring.data.mongodb.uri=mongodb://192.168.22.110:27017/myfirstMongodb
2 
3 #spring.profiles.active
4 spring.profiles.active=dev
View Code

说明:上边的配置表示使用dev环境下的配置。

注意:spring.data.mongodb.uri=mongodb://192.168.22.110:27017/myfirstMongodb该配置是application-dev.properties没有的配置

4、Controller

技术分享
1     @Autowired
2     private Environment env;
3         
4     @RequestMapping("/testProfile")
5     public String testProfile(){
6         return env.getProperty("profile");
7     }
View Code

 

测试

结论:

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!