Skip to content

Commit 334bcdb

Browse files
committed
App.java
App.java
1 parent 653d55e commit 334bcdb

File tree

1 file changed

+15
-5
lines changed
  • spring-profile/src/main/java/com/hmkcode

1 file changed

+15
-5
lines changed

spring-profile/src/main/java/com/hmkcode/App.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.hmkcode;
22

3+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
34
import org.springframework.context.support.ClassPathXmlApplicationContext;
45
import org.springframework.context.support.GenericXmlApplicationContext;
56
import org.springframework.core.env.ConfigurableEnvironment;
67

8+
import com.hmkcode.spring.SpringConfig;
79
import com.hmkcode.vo.Person;
810

911

1012
public 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
}

0 commit comments

Comments
 (0)