spring3的properties文件的开发正式环境配置

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


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值