Our projects generally run in the formal environment and the test environment. When packaging or running, switching database information may be a very troublesome problem.
Configuration method:
1. Configure two kinds of environment information in the spring configuration file
[html] view plain copy
- <beans profile="dev">
- <context:property-placeholder location="classpath:jdbc-dev.properties"/>
- </beans>
- <beans profile="prd">
- <context:property-placeholder location="classpath:jdbc-prd.properties"/>
- </beans>
2. Configure which environment information to use in web.xml, and automatically load the corresponding environment information when tomcat starts.
[html] view plain copy
- <context-param>
- <param-name>spring.profiles.active</param-name>
- <param-value>dev</param-value>
- </context-param>