spring profile多配置文件的切换
2017-02-09 14:31
225 查看
老生常谈的问题 开发环境 测试环境 生产环境分别对应的properties配置文件在最少改动代码的基础上进行灵活的切换三个配置文件分别为 local.properties,test.properties,production.properties1.在spring的配置文件里加上代码<!-- 测试环境配置文件 --> <beans profile="test"> <context:property-placeholder location="classpath:test.properties" /> <util:properties id="APP_PROP" location="classpath:test.properties" local-override="true"/> </beans> <!-- 本地环境配置文件 --> <beans profile="local"> <context:property-placeholder location="classpath:local.properties" /> <util:properties id="APP_PROP" location="classpath:local.properties" local-override="true"/> </beans> <!-- 生产环境配置文件 --> <beans profile="local"> <context:property-placeholder location="classpath:production.properties" /> <util:properties id="APP_PROP" location="classpath:production.properties" local-override="true"/> </beans>util:properties是用@Value注解来引入配置文件中的变量2.然后在web.xml文件中设置默认指向(我这里指向的是local)<context-param> <param-name>spring.profiles.default</param-name> <param-value>local</param-value> </context-param> 3.然后就是激活你想要的配置文件这里网上有很多方法 比如在web.xml文件里加入<context-param> <param-name>spring.profiles.default</param-name> <param-value>local</param-value> </context-param> 考虑到尽量少的改动代码,我这里在tomcat 的启动脚本中加入以下 JVM参数 来激活
-Dspring.profiles.active="xxx"
本地开发环境用默认的local
测试环境的tomcat启动脚本中加入
-Dspring.profiles.active="test"
生产环境的tomcat启动脚本中加入
-Dspring.profiles.active="production"
好了,大功告成
相关文章推荐
- spring配置文件---之数据库切换
- Java类中@Profile注解 springboot切换不同环境配置
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 使用Spring3.1后的的Profile配置使不同环境加载不同配置文件
- Spring boot 切换配置文件到yaml
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Spring.profile实现开发、测试和生产环境的配置和切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Gradle项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Springboot使用maven的profiles实现多环境配置文件切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Spring-Boot使用profile来配置不同环境的配置文件
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- spring使用profile选择配置文件
- SpringBoot内部配置:“application.properties配置”和”使用XML配置”,读取属性文件中的内容,日志配置,Profile配置(学习:SpringBoot实战)
- Spring-Boot使用profile来配置不同环境的配置文件