Skip to content

Commit 25725d7

Browse files
committed
App.java
App.java
1 parent 893fda4 commit 25725d7

File tree

1 file changed

+35
-0
lines changed
  • spring-profile/src/main/java/com/hmkcode

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)