File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
spring-profile/src/main/java/com/hmkcode Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 11package com .hmkcode ;
22
3+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
34import org .springframework .context .support .ClassPathXmlApplicationContext ;
45import org .springframework .context .support .GenericXmlApplicationContext ;
56import org .springframework .core .env .ConfigurableEnvironment ;
67
8+ import com .hmkcode .spring .SpringConfig ;
79import com .hmkcode .vo .Person ;
810
911
1012public class App
1113{
1214 public static void main ( String [] args )
1315 {
14-
16+
1517 // ( 1 ) System.setProperty("spring.profiles.active", "development");
16- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("spring-config-all.xml" );
18+ // ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config-all.xml");
1719
1820 // ( 2 )
19- ConfigurableEnvironment env = ctx .getEnvironment ();
21+ /* ConfigurableEnvironment env = ctx.getEnvironment();
2022 env.setActiveProfiles("development");
21- ctx .refresh ();
23+ ctx.refresh(); */
2224
2325 //( 3 )
2426 /*GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
@@ -28,7 +30,15 @@ public static void main( String[] args )
2830 ctx.refresh();*/
2931
3032 //( 4 ) combine
31- Person person = ctx .getBean ("person" , Person .class );
33+
34+
35+ //( 5 )
36+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
37+ ctx .getEnvironment ().setActiveProfiles ("development" );
38+ ctx .register (SpringConfig .class );
39+ ctx .refresh ();
40+ Person person = (Person )ctx .getBean ("person" );
41+
3242
3343 System .out .println ("Person: " +person );
3444 }
You can’t perform that action at this time.
0 commit comments