- Object object;
- ConfigurableApplicationContext ctx = new GenericXmlApplicationContext();
- ConfigurableEnvironment env = ctx.getEnvironment();
- MutablePropertySources propertySources = env.getPropertySources();
- try {
- propertySources.addLast(new ResourcePropertySource("classpath:app.properties"));
- System.out.println(env.getProperty("property1"));
- System.out.println(env.getProperty("property2"));
- } catch (IOException e) {}
- GenericXmlApplicationContext gCtx = (GenericXmlApplicationContext) ctx;
- gCtx.load("clathpath:appContext.xml");
- gCtx.refresh();
- object = gCtx.getBean("beanID", Object.class);
- // ConfigurableApplicationContext 즉, ctx에는 propertySouce로 app.properties
- // 파일의 내용이 들어가 있다.
- // 이 내용과 더불어 GenericXmlApplicationContext 즉, gCtx에서 appContext.xml 리소스를
- // 함께 사용하고 있다.
- // 이 경우 ctx.getBean()으로 부터 주입된 객체는 app.properties의 내용과 appContext.xml
- // 모두의 설정을 사용할 수있다.
- /* do something */
- ctx.close();
2015년 12월 10일 목요일
Environment 객체를 이용한 스프링 빈 설정
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기