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

摘要:
//www.jianshu.com/p/948c303b2253spring mvc hibernate.xml<beansprofile=“dev”>beansprofile=“测试”>beansprofile=“prod”>--&书信电报;参数值>/参数值><-->

前两篇不错

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.91]# 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包,实现开发、测试和生产环境的按需切换》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇svn使用方法以及使用教程安卓开发实战-记账本APP(六)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

eclipse导入maven项目有红叉及pom.xml出错的问题的解决

导入我们的项目的时候总会出现很多红叉,看着很难受,其实可以解决的(本人使用方法一解决)解决方法:1、先build project,然后右键项目->maven->update projectpom还是有问题就到这个目录,打开命令行,mvn clean->mvn eclipse:clean->mvn eclipse:eclipse 基本...

(转载)Qt中的类型转换

(转载)http://blog.csdn.net/xuhongtao123459/article/details/5810101 把QString转换为 double类型 方法1.QString str="123.45"; double val=str.toDouble(); //val=123.45 方法2.很适合科学计数法形式转换 bool ok; d...

ReactNative--组件的样式

设置组件的样式,讲解三种: 1 内联样式 2 对象样式 3 选择器样式 注意:在React和HTML5中设置样式时的书写格式是有一定区别的 1 HTML5以;结尾 React以,结尾 2 HTML中key,value都不加引号 React中属于JavaScript对象,key的名字不能出现"-",需要使用驼峰命名法。如果value为字符串,需要加引号...

1046

Gridland Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4127 Accepted Submission(s): 1900 Problem Description For y...

小程序换行符检测换行

先将换行符替换成自定义连接字符 var goods_detail = "" if(res.data.info.goods_info.goods_detail){ goods_detail = res.data.info.goods_info.goods_detail; var str=goods_detail.replace(/ /g,"|-&")...

asp.net core 集成JWT(二)token的强制失效,基于策略模式细化api权限

【前言】   上一篇我们介绍了什么是JWT,以及如何在asp.net core api项目中集成JWT权限认证。传送门:https://www.cnblogs.com/7tiny/p/11012035.html   很多博友在留言中提出了疑问: 如何结合jwt认证对用户进行API授权? token过期了怎么办? 如何自动刷新token? 如何强制toke...