문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
springframework:propertysource [2012/10/20 22:11] kwon37xi [PropertySource] |
springframework:propertysource [2017/08/11 09:04] (현재) kwon37xi |
||
---|---|---|---|
줄 4: | 줄 4: | ||
* 시스템 프라퍼티, | * 시스템 프라퍼티, | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
===== 프라퍼티 추가 ===== | ===== 프라퍼티 추가 ===== | ||
* 일반 프라퍼티 파일의 경우 | * 일반 프라퍼티 파일의 경우 | ||
* Java 클래스 설정에서는 [[http:// | * Java 클래스 설정에서는 [[http:// | ||
- | * [[http:// | + | * <del>[[http:// |
===== 코딩을 통한 임의의 프라퍼티 소스 추가 ===== | ===== 코딩을 통한 임의의 프라퍼티 소스 추가 ===== | ||
줄 25: | 줄 25: | ||
< | < | ||
</ | </ | ||
+ | </ | ||
+ | * TestContext에서 '' | ||
+ | @ContextConfiguration(initializers = MyInitializer.class) | ||
</ | </ | ||
* '' | * '' | ||
줄 34: | 줄 37: | ||
} | } | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ==== ApplicationContextInitializer를 Java 코드 기반 ApplicationContext에서 사용하기 ==== | ||
+ | * [[http:// | ||
+ | // Create context, but dont initialize with configuration by calling | ||
+ | // the empty constructor. Instead, initialize it with the Context Initializer. | ||
+ | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | ||
+ | MyAppContextInitializer initializer = new MyAppContextInitializer(); | ||
+ | |||
+ | // ApplicationContextInitializer가 ApplicationContext를 초기화해주는 형태 | ||
+ | initializer.initialize( ctx ); | ||
+ | |||
+ | // @Configuration 클래스를 등록하고 초기화 | ||
+ | ctx.register( com.my.classpath.StackOverflowConfiguration.class ); | ||
+ | ctx.refresh() | ||
</ | </ | ||
==== @Configuration 클래스에서 XML 프라퍼티를 프라퍼티 소스로 등록하기 예제 ==== | ==== @Configuration 클래스에서 XML 프라퍼티를 프라퍼티 소스로 등록하기 예제 ==== | ||
+ | **3.2 최신 버전에서는 이 기법을 사용할 필요가 없다. ApplicationContextInitializer를 사용하자.** | ||
현재(3.1.2) '' | 현재(3.1.2) '' | ||
[[http:// | [[http:// | ||
줄 88: | 줄 107: | ||
===== PlaceHolder로 사용하기 ===== | ===== PlaceHolder로 사용하기 ===== | ||
- | PropertySource에 등록된 프라퍼티들을 '' | + | PropertySource에 등록된 프라퍼티들을 '' |
* Java 코드 설정시< | * Java 코드 설정시< | ||
@Configuration | @Configuration | ||
줄 111: | 줄 130: | ||
--> | --> | ||
</ | </ | ||
+ | |||
+ | ===== ResourceLoader ===== | ||
+ | * '' | ||
+ | * 단, '' | ||
+ | * 그냥 속 편하게 [[http:// | ||
+ | |||
+ | ===== @Value ===== | ||
+ | ==== @Value로 Date 객체 주입하기 ==== | ||
+ | * [[http:// | ||
+ | @Value("# | ||
+ | private Date date; | ||
+ | </ | ||
+ | * [[http:// |