前两篇不错

Spring.profile实现开发、测试和生产环境的配置和切换 - Strugglion - 博客园
https://www.cnblogs.com/strugglion/p/7091021.html

详解Spring中的Profile - 简书
https://www.jianshu.com/p/948c303b2253

spring-mvc-hibernate.xml

    <!-- JSR303 Validator定义 -->
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <!-- 引入属性文件 -->
<!-- 基于Spring Profile机制的database连接配置 -->
<!-- 开发环境配置文件 -->
<beans profile="dev">
<context:property-placeholder location="classpath:profiles/dbconfig_dev.properties" ignore-unresolvable="true" />
</beans>
<!-- 测试环境配置文件 -->
<beans profile="test">
<context:property-placeholder location="classpath:profiles/dbconfig_test.properties" ignore-unresolvable="true" />
</beans>
<!-- 生产环境配置文件 -->
<beans profile="prod">
<context:property-placeholder location="classpath:profiles/dbconfig_prod.properties" ignore-unresolvable="true" />
</beans>
</beans>

web.xml

    <!-- 设置spring.profiles.active后则spring.profiles.default失效,web启动时会加载对应的环境信息 -->
<!-- 为了适应jenkins的持续集成发布crm.war方案,在tomcat的bin/setenv.sh中追加如下参数:-Dspring.profiles.active="xxxx"。xxx为dev/test/prod其中之一。 -->
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
<!--
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>prod</param-value>
</context-param>
-->

 setenv.sh

[root@crm_web apache-tomcat-7.0.]# cat bin/setenv.sh
CATALINA_OPTS="$CATALINA_OPTS -Dspring.profiles.active=test -Djava.rmi.server.hostname=192.168.66.16 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access"

setenv.bat

set CATALINA_OPTS=-Dspring.profiles.active=test -Djava.rmi.server.hostname=192.168.66.182 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access

注意事项:

1.spring.profiles.active

2.profile 特性是在spring3.1中引入的,3.0还不支持。xml配置中的spring-beans-3.0.xsd,在3.0中解析不到3.1中的profile,所以必须替换成spring-beans-3.1.xsd

  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

3.Nested <beans> must appear last in the file.

  https://dzone.com/articles/spring-31-environment-profiles

    Nested <beans> must appear last in the file.

    文件有正确顺序的标签示例。

  https://stackoverflow.com/questions/33869324/spring-profile-and-property-placeholder-exception

    I would try to re-order the application context file, having the two profiles before <context:property-placeholder properties-ref="deployProperties" />.

  http://www.cnblogs.com/davidwang456/p/4204569.html

   // Any nested <beans> elements will cause recursion in this method. In
// order to propagate and preserve <beans> default-* attributes correctly,
// keep track of the current (parent) delegate, which may be null. Create
// the new (child) delegate with a reference to the parent for fallback purposes,
// then ultimately reset this.delegate back to its original (parent) reference.
// this behavior emulates a stack of delegates without actually necessitating one.
   还得多读源码,如果不把<beans>放在<bean>,会导致循环引用的问题。

官方参考

3. New Features and Enhancements in Spring Framework 3.1
https://docs.spring.io/spring-framework/docs/3.2.0.RELEASE/spring-framework-reference/html/new-in-3.1.html

Spring 3.1 M2: Testing with @Configuration Classes and Profiles
http://spring.io/blog/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles/

Spring 3.1 M1: Introducing @Profile
http://spring.io/blog/2011/02/14/spring-3-1-m1-introducing-profile/

Spring Framework 3.1 M1 released
http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/

11. Testing
https://docs.spring.io/spring-framework/docs/3.2.0.RELEASE/spring-framework-reference/html/testing.html#testcontext-framework

cbeams/spring-3.1-profiles-java: Sample demonstrating use of Spring 3.1's 'bean definition profiles' feature with @Configuration classes
https://github.com/cbeams/spring-3.1-profiles-java

Spring Framework Reference Documentation
http://files.cnblogs.com/files/kongkaikai/spring-framework-reference.pdf

Introduction · Spring Framework 4.x参考文档
http://blog.didispace.com/books/spring-framework-4-reference/

 

以下的作为参考

Spring实战——Profile - JackieZheng - 博客园
http://www.cnblogs.com/bigdataZJ/p/SpringInAction4.html

通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换 - 许恕 - CSDN博客
https://blog.csdn.net/xvshu/article/details/51133786

详解Spring中的Profile - 王云十三 - 博客园
https://www.cnblogs.com/SummerinShire/p/6392242.html

详解Spring中的Profile - 刘剑峰的博客 - CSDN博客
https://blog.csdn.net/jeffleo/article/details/71433655

spring @profile注解的使用 - 止水的专栏 - CSDN博客
https://blog.csdn.net/wild46cat/article/details/71189858

Spring.profile配合Jenkins发布War包,实现开发、测试和生产环境的按需切换的更多相关文章

  1. 【Spring】使用@Profile注解实现开发、测试和生产环境的配置和切换,看完这篇我彻底会了!!

    写在前面 在实际的企业开发环境中,往往都会将环境分为:开发环境.测试环境和生产环境,而每个环境基本上都是互相隔离的,也就是说,开发环境.测试环境和生产环境是互不相通的.在以前的开发过程中,如果开发人员 ...

  2. jenkins发布.war包到本地tomcat

    前提:保证jenkins构建打包成功 1.配置tomcat的用户名密码(此处tomcat为本地任意tomcat包,jenkins会通过Deploy war/ear to container配置的url ...

  3. 推荐几位jenkins发布war包和jar包大佬的博客

    jenkins部署tomcat的war包和jar包 https://blog.csdn.net/liuxiaoming1109/article/details/89311696  

  4. Spring.profile实现开发、测试和生产环境的配置和切换

    软件开发过程一般涉及“开发 -> 测试 -> 部署上线”多个阶段,每个阶段的环境的配置参数会有不同,如数据源,文件路径等.为避免每次切换环境时都要进行参数配置等繁琐的操作,可以通过spri ...

  5. Spring Boot发布war包流程

    1.修改web model的pom.xml <packaging>war</packaging> SpringBoot默认发布的都是jar,因此要修改默认的打包方式jar为wa ...

  6. 【Linux】Jenkins以war包运行及开机启动配置(四)

    本例介绍jenkins已war包运行及开机启动配置 环境:Linux环境(CentOS 7.4) 以war包运行 1.下载jenkins.war包 2.启动war包( 默认端口:8080,默认JENK ...

  7. Liferay 6.2 改造系列之二十二:如何发布WAR包

    1.修改web资源并发布 如果修改了默认主题信息,需执行portal-web中的build-themes任务: 执行portal-web中的deploy任务: 2.修改portal-impl中的jav ...

  8. jenkins部署war包到远程服务器的tomcat

    一.目的 jenkins上将war包,部署到远程服务器的tomcat上. 这边tomcat在windows 主机A上,版本apache-tomcat-8.5.23. jenkins在主机B上,cent ...

  9. 使用Tomcat发布war包

    第一步:下载tomacat 1.下载地址:http://tomcat.apache.org 2.解压后目录如下 3.双击bin文件夹下startup.bat 即可启动tomcat, 计算机会弹出控制台 ...

随机推荐

  1. 创建两个SAP系统之间的RFC信任关系

    一种常见的场景是企业运行着多个SAP系统(ERP/SRM/CRM),用户希望在AA1系统中使用BB1系统的事务.如果直接使用RFC调用另一系统的事务的话,则会弹出登陆框,让用户再次输入帐号密码... ...

  2. Why do Kafka consumers connect to zookeeper, and producers get metadata from brokers?

    Why do Kafka consumers connect to zookeeper, and producers get metadata from brokers? Ask Question u ...

  3. vue源码分析—数据绑定

    放进沙里附件拉萨就发牢骚:剑飞:啊撒

  4. ES5-ES6-ES7_字符串与JOSN格式的数据相互转换以及深度克隆新对象

    这篇文章主要来讲HTML5中的新方法:parse()把字符串转换成josn格式的数据和stringify()把josn格式的数据转换成字符串 eval()方法的回顾 eval()方法可以将任何字符串解 ...

  5. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)

    前言:原来一直使用MyEclipse,换工作后,新公司使用IDEA,初识IDEA发现,哇,它的快捷键可真多啊,但是一路用下来,觉得非常的好用,特别是利用Maven管理,那简直叫一个爽.当然笔者在使用过 ...

  6. centos7下安装docker(16.1docker跨主机存储--Rex-Ray)

    一.Rex-Ray以standalone进程的方式运行在docker主机上,安装方法很简单:在docker1和docker2上运行如下命令: curl -sSL https://dl.bintray. ...

  7. 发现电脑上装着liteide,就用golang做一个TCP通讯测试(支持先启动client端和断线重连)

    1.参考https://www.cnblogs.com/yin5th/p/9274495.html server端 main.go package main import ( "fmt&qu ...

  8. Python学习笔记(1)-列表

    列表是什么? 列表由一系列按特定顺序排列的元素组成.列表看起来像这样:[1,2,3,4,1].在列表中,可以由零个或多个元素组成,元素之间用逗号分开,具有相同值元素允许出现多次 使用[ ]或list( ...

  9. 五、Oracle 分组查询、视图

    一.分组函数1.avg:平均分2.sum:求和3.max:最大值4.min:最小值注意:前面四个必须针对数值字段,且参数只能是一个5.count:求个数 二.分组查询1.语法是 group by 分组 ...

  10. 13 python初学(函数)

    函数: 概念:函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 创建: def 函数名命名规范: a. 必须以下划线或字母开头 b. 区分大小写 c.不能 ...