spring.profiles.active spring configuration for multiple startup environments

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

  1. <beans profile="dev">  
  2.         <context:property-placeholder location="classpath:jdbc-dev.properties"/>  
  3.     </beans>  
  4.     <beans profile="prd">  
  5.         <context:property-placeholder location="classpath:jdbc-prd.properties"/>  
  6.     </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

  1. <context-param>  
  2.         <param-name>spring.profiles.active</param-name>  
  3.         <param-value>dev</param-value>  
  4.     </context-param>  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343224&siteId=291194637