Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발용

[Spring] IoC 본문

개발/WEB

[Spring] IoC

DeP 2017. 1. 24. 14:33

 

<pre>

resource :: 환경설정 파일 ex) applicationContext.xml

<bean id="[REF_KEY]" class="[CLASS_NAME]" scope="singleton/prototype"></bean>        //반드시 패키지 경로 포함 -> ctrl + space 권장

 

 

<step>

1. spring 컨테이너 구동

AbstractApplicationContext factory = new GenericXmlApplicationContext("classpath:applicationContext.xml");

//applicationContext.xml을 로딩하여 스프링 컨테이너 중 하나인 GenericXmlApplicationContext를 구동

 

2. spring 컨테이너로부터 필요한 객체를 요청

[CLASS_NAME] [REF_NAME] = (CLASS_NAME)factory.getBean("[REF_KEY]");

//CLASS_NAME에 존재하는 필요한 메소드 사용

//...

 

3. spring 컨테이너 종료

factory.close();

 

 

 

- [CLASS_NAME]에 새로운 클래스를 넣는 경우 모든 .java파일을 수정하지 않아도 된다.

- applicationContext.xml 파일만 수정하면 된다. => 유지보수 편리

 

 

 

 

 

 

'개발 > WEB' 카테고리의 다른 글

[Spring] AOP  (0) 2017.01.24
[Spring] 어노테이션 기반 설정  (0) 2017.01.24
[Spring] DI(의존성 주입)  (0) 2017.01.24
Bean factory  (0) 2017.01.24