摘要: 当开发环境、测试环境及生产环境需要不同的dataSource时,可以采用spring的profile定义多个数据源
1.在Spring配置文件中定义开发、测试环境和生产环境
<beans profile="test,develop">
<!-- 开发和测试环境 -->
</beans>
<beans profile="product">
<!-- 生产环境 -->
</beans>
2.在web.xml中, 指定使用哪种环境
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>test</param-value>
</context-param>
或者
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>product</param-value>
</init-param>
</servlet>
或者
-Dspring.profiles.active="profile1,profile2"