此处定义了不同环境下不同的数据库链接信息
3、web.xml中定义当前使用哪个环境
在web.xml中操作context-param节点
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>product</param-value>
</context-param>
部署时指定哪个环境为激活状态即可。
如果进行junit测试可以使用
@ActiveProfiles({"test","develop"})
附: 如果spring的profile可以和maven的发布共同作用就更好了,但是笔者目前还未能成功将2者结合。
配置提醒:
<beans xmlns="http://www.springframework.org/schema/beans" profile="test,develop" -----设置这个之后,数据库只对test,develop有效
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- 定义数据连接池 -->
<!-- 使用spring自带的DriverManagerDataSource方式 -->