通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
来源:互联网 发布:石家庄网络布线及维护 编辑:程序博客网 时间:2024/06/05 05:56
1、在resources目录下创建applicationContext-profile.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"
default-lazy-init="true">
<description>Spring公共配置 </description>
<beans profile="production">
<context:property-placeholder ignore-unresolvable="true"
location="classpath*:common/*.properties, classpath*:production/*.properties" />
</beans>
<beans profile="test">
<context:property-placeholder ignore-unresolvable="true"
location="classpath*:common/*.properties, classpath*:test/*.properties" />
</beans>
<beans profile="dev">
<context:property-placeholder ignore-unresolvable="true"
location="classpath*:common/*.properties, classpath*:dev/*.properties" />
</beans>
</beans>
2、在resources目录下创建common【公共文件】、production【正式环境】、test【测试环境】、dev【开发环境】等目录,并存放相应环境的properties文件
3、在spring-mvc.xml文件加载上面创建的applicationContext-profile.xml文件:
<import resource="classpath*:/applicationContext-profile.xml"/>
4、在pom.xml文件添加默认的环境
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.activation>dev</profiles.activation>
</properties>
</profile>
</profiles>
5、tomcat服务器的catalina.sh文件启动参数设置:
#正式:
JAVA_OPTS="-Dspring.profiles.active=production"
#开发:
JAVA_OPTS="-Dspring.profiles.active=dev "
#测试:
JAVA_OPTS="-Dspring.profiles.active=test"
参考资料:
http://sishuok.com/forum/blogPost/list/7936.html
http://www.blogjava.net/paulwong/archive/2014/03/28/411596.html
https://www.cnblogs.com/strugglion/p/7091021.html
https://www.cnblogs.com/yilunzhang/p/7838708.html
http://blog.csdn.net/wantken/article/details/31764609
转自:http://blog.csdn.net/thinkfly123thinkfly/article/details/51094083
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- spring容器内建的profile功能实现开发环境、测试环境、生产环境配置自动切换
- 实现开发环境、测试环境、生产环境配置自动切换
- 实现开发环境、测试环境、生产环境配置自动切换
- Gradle项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- Maven项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- 通过gradle实现自动切换测试环境和线上环境
- Maven 整合 spring profile实现多环境自动切换
- Maven 整合 spring profile实现多环境自动切换
- maven整合spring profile实现多环境自动切换
- maven的profile配置多种部署环境(如开发、测试、生产等)
- MSSQL · 最佳实践 · SQL Server三种常见备份
- C# pdf 解决既要横向又要竖向的页问题
- cmd常用命令
- TCP面试常见题:time_wait状态产生的原因,危害,如何避免
- Duilib 源码分析之 CControlUI 篇
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- HUD 1576 A/B【逆元 -> 扩展欧几里得】
- 关于自定义 TabBar 新的思路及演练 (衍生的bug解决)
- Java中instanceof关键字的用法总结
- Git详解之Git起步
- 《android多媒体api》之camera配合surface预览相机画面和拍照
- python
- vue-router 多层嵌套
- BBB学习(五):Windows电脑通信调试(1):debug口