第一步:

applicationContext.xml

    <!--环境配置开始-->
<beans profile="production">
<context:property-placeholder
ignore-resource-not-found="true" location="classpath:config.prod.properties"/>
</beans> <beans profile="development">
<context:property-placeholder
ignore-resource-not-found="true" location="classpath:config.dev.properties"/>
</beans>

第二步:

配置web.xml

    <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param> <!--测试环境-->
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>development</param-value>
</context-param> <!--生产环境-->
<!--<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>prod</param-value>
</context-param>-->

第三步:

其重点难点:

Windows系统中,修改tomcat  start.bat文件,在第一行加入:

SET JAVA_OPTS="-Dspring.profiles.active=prod"

Linux 系统中,修改tomcat  catlina.sh文件,在第一行加入:

CATALINA_OPTS="$CATALINA_OPTS -Dspring.profiles.active=\"prod\""

或者

JAVA_OPTS="-Dspring.profiles.active=\"production\""

Window 系统中查看是否设置成功:

打开%jdk_home%\bin 中的 jvisualvm.exe  界面即可:

使用spring profile实现多环境切换的更多相关文章

  1. Maven 整合 spring profile实现多环境自动切换

    Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...

  2. Spring9——通过用Aware接口使用Spring底层组件、环境切换

    通过用Aware接口使用Spring底层组件 能够供我们使用的组件,都是Aware的子接口. ApplicationContextAware:实现步骤:             (1)实现Applic ...

  3. spring Profile 为不同环境提供不同的配置支持

    说明 Profile为在不同环境下使用不同的配置提供了支持(开发环境下的配置和生产环境下的配置肯定是不同的, 例如, 数据库的配置) . 在spring开发中用@Profile 注解使用来选择行配置系 ...

  4. Maven+Spring Profile实现生产环境和开发环境的切换

    第一步 Maven Profile配置 <profiles> <profile> <id>postgres</id> <activation> ...

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

    前两篇不错 Spring.profile实现开发.测试和生产环境的配置和切换 - Strugglion - 博客园https://www.cnblogs.com/strugglion/p/709102 ...

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

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

  7. 使用Spring Profile和Mybatis进行多个数据源(H2和Mysql)的切换

    最近在做WebMagic的后台,遇到一个问题:后台用到了数据库,本来理想情况下是用Mysql,但是为了做到开箱即用,也整合了一个嵌入式 数据库H2.这里面就有个问题了,如何用一套代码,提供对Mysql ...

  8. Spring Boot入门(二):使用Profile实现多环境配置管理&如何获取配置文件值

    在上一篇博客Spring Boot入门(一):使用IDEA创建Spring Boot项目并使用yaml配置文件中,我们新建了一个最原始的Spring Boot项目,并使用了更为流行的yaml配置文件. ...

  9. Maven之profile实现多环境配置动态切换

            一般的软件项目,在开发.测试及生产等环境下配置文件中参数是不同的.传统的做法是在项目部署的时候,手动修改或者替换这个配置文件.这样太麻烦了,我们可以用Maven的profile来解决这 ...

随机推荐

  1. RFC destination fails with error Incomplete Logon Data after system copy

    1. 问题现象 1.1在system copy后,提示RFC报错Unable to configure STMS 2.  重要的参考文件: 2.1RFC passwords not available ...

  2. FreeRTOS config开始的宏

    FreeRTOSConfig.h系统配置文件中可以自定义,FreeRTOS.h中定义默认值 configAPPLICATION_ALLOCATED_HEAP 默认情况下FreeRTOS的堆内存是由编译 ...

  3. Jerry带您了解Restful ABAP Programming模型系列之二:Action和Validation的实现

    相信通过Jerry的前一篇文章 30分钟用Restful ABAP Programming模型开发一个支持增删改查的Fiori应用,想必大家对Restful ABAP Programming模型已经有 ...

  4. [#Linux] CentOS 7 禁用笔记本的触摸板

    安装 xorg-x11-apps yum install xorg-x11-apps 查看对应设备的 id xinput –list 关闭 touchpad xinput set-int-prop 1 ...

  5. python编码和解码

    一.什么是编码 编码是指信息从一种形式或格式转换为另一种形式或格式的过程. 在计算机中,编码,简而言之,就是将人能够读懂的信息(通常称为明文)转换为计算机能够读懂的信息.众所周知,计算机能够读懂的是高 ...

  6. 制作一个简单的部门员工知识分享的python抽取脚本

    需求: 基于公司的文化和公司部门间以及员工之间的工作需求状态,或者想要了解某一些技能.专业方面的知识需求.促进并提高员工们的技能认知和技术水平. 详细代码如下: 先说一下存入csv表格的表头字段: 1 ...

  7. {RuntimeError} An attempt has been made to start a new process before the current process has finished its bootstrapping phase.This probably means that you are not using fork to start your child...

    加载数据时出现报错: RuntimeError:         An attempt has been made to start a new process before the        c ...

  8. 19 Jquery 属性

    从 jQuery 1.6 开始, .prop()方法 方法返回 property 的值,而 .attr() 方法返回 attributes 的值. 例如, selectedIndex, tagName ...

  9. js闭包随记

    理解闭包可以将以上代码分解如下: function outerFunction() {     ;     function innerFunction(){         return count ...

  10. vue app.xxx.js 较大问题

    线上build之后发现app.XXX.js 文件特别大. 包我都改为cdn了 其他空间就是路由改为懒加载了. { path: '/a/b', name: 'ab', component: () =&g ...