Spring activation profile way

Spring activation profile method: Setting these two properties spring.profiles.active and spring.profiles.default
Setting local activation profile properties (in the end by the high priority)
0) Spring context
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
ConfigurableEnvironment env = ctx.getEnvironment();
or
ApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
Environment _e =ctx.getEnvironment();
ConfigurableEnvironment env = ConfigurableEnvironment.class.cast(_e);
// set by setActiveProfiles.
env.setActiveProfiles("wow","pes","ff"); 
// container must be rebuilt
ctx.refresh();
 
1)ServletConfig parameters(if applicable, e.g. in case of a DispatcherServlet context)
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</init-param>
 
2)ServletContext parameters(web.xml context-param entries)
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
 
3)JNDI environment variables
 
4)JVM system properties
JVM system properties of the arrangement
a) providing the JVM startup parameters -D <name> = <value> ( "-D" command-line arguments)
   i) catalina.bat (.sh are not "set") in the tomcat added JAVA_OPTS = "- Dspring.profiles.active = dev"
   ii) eclipse set run configuration: -Dspring.profiles.active = dev
b) JAVA standard API:
   System.setProperty ( "spring.profiles.active", "dev"); // before the start of the container, specify the parameters of the environment profiles
   ApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
   
5) OS environment variable
  Increase environmental variables, eg.spring.profiles.active = dev
  读取配置文件 <context:property-placeholder location="classpath:config_${spring.profiles.active}.properties" ignore-unresolvable="true"  />
 
 
JNDI environment variables ("java:comp/env/" entries)

 
In the integrated test class, using @ActiveProfiles annotation configuration.

Guess you like

Origin www.cnblogs.com/tsai-87/p/10983424.html