File tree 1 file changed +35
-0
lines changed
spring-profile/src/main/java/com/hmkcode
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .hmkcode ;
2
+
3
+ import org .springframework .context .support .ClassPathXmlApplicationContext ;
4
+ import org .springframework .context .support .GenericXmlApplicationContext ;
5
+ import org .springframework .core .env .ConfigurableEnvironment ;
6
+
7
+ import com .hmkcode .vo .Person ;
8
+
9
+
10
+ public class App
11
+ {
12
+ public static void main ( String [] args )
13
+ {
14
+
15
+ // ( 1 ) System.setProperty("spring.profiles.active", "development");
16
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("spring-config-all.xml" );
17
+
18
+ // ( 2 )
19
+ ConfigurableEnvironment env = ctx .getEnvironment ();
20
+ env .setActiveProfiles ("development" );
21
+ ctx .refresh ();
22
+
23
+ //( 3 )
24
+ /*GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
25
+ ConfigurableEnvironment env = ctx.getEnvironment();
26
+ env.setActiveProfiles("production");
27
+ ctx.load("spring-config-development.xml","spring-config-production.xml");
28
+ ctx.refresh();*/
29
+
30
+ //( 4 ) combine
31
+ Person person = ctx .getBean ("person" , Person .class );
32
+
33
+ System .out .println ("Person: " +person );
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments