1. IOC & Spring Framework 이수안(inch772@naver.com) 아꿈사(http://cafe.naver.com/architect1.cafe)
2.
3.
4.
5.
6.
7. Inversion of Control 객체들이 다른 객체를 invoke하는 구조가 아닌 의존되는 객체가 외부 엔터티나 컨테이너에 의해 삽입되는 구조 헐리우트 원칙 “don’t call me I will call you” Dependency injection Runtime 시점에 컨테이너에 의해 의존성들이 ‘삽입’ 된다. Bean 생성시 생성자파라메터나프로퍼티를 통해 의존성이 연결된다. 객체나 서비스 Lookup이나 객체 생성등의 하드코팅을 예방한다. 의존성을 약하게 한다. Unit Test를 효과적으로 작성하게 해준다.
11. publicclassCampaignServiceImplimplementsCampaignService{ public Campaign updateCampaign(Campaign campaign) throws CampaignException{ try{ oppDAO.save(campaign); }catch(Exception e){ } } // Spring sets the value thru runtime injection! private setOpportunityDAO(OpportunityDAOoppDao){ this.oppDAO = oppDao; } IoC Service Object
12. 객체의 생성, 생성 후 초기화, 서비스 실행, 소멸에 관한 모든 권한을 가지면서 생명주기를 관리한다. 예: Servlet Container, EJB Container 컨테이너? Service Init Create Destory Container 객체A 객체 B 객체C 객체 D
13. POJO(Plain old Java Object) Servlet과 EJB와 같이 특정 API에 종속적이지 않은 모든 자바 클래스. 일반적으로 우리들이 흔히 이야기하는 자바빈은 모두 POJO라고 이야기할 수 있다. Spring & POJO Spring의 기본 객체 관리 단위는 POJO 임 Spring은 POJO의 객체의 Life Cycle을 관리하는 IoC컨테이너 역할을 제공한다. POJO?
14. IoC(또는 DI) Container POJO의 생성, 초기화, 서비스 소멸에 관한 모든 권한을 가지면서 POJO의 생명주기를 관리한다. 개발자들이 직접 POJO를 생성할 수도 있지만, 모든 권한을 Container에게 맡긴다. Transaction, Security 추가적인 기능을 제공한다. AOP 기능을 이용하여 새로운 Container 기능을 추가하는 것이 가능하다 IoC Container Service Init Create Destory IoC(또는 DI) Container POJO A POJO B POJO C POJO D
18. A lightweight non-intrusive framework which addresses various tiers in a J2EE application. What is Spring Framework?
19. Not a J2EE container. Doesn’t compete with J2EE app servers. Simply provides alternatives. POJO-based, non-invasive framework which allows a la carte usage of its components. Promotes decoupling and reusability Reduces coding effort and enforces design discipline by providing out-of-box implicit pattern implementations such as singleton, factory, service locator etc. Removes common code issues like leaking connections and more Support for declarative transaction management Easy integration with third party tools and technologies. Spring Benefits
20. IoC객체를 직접 생성하지 않고 외부에서 전달 받는 구조 IoC컨테이너는 POJO의 생명 주기를 관할한다. 대표적인 POJO 기반 IoC컨테이너는 Spring Framework Spring FrameWorkPOJO-based, non-invasive framework IoC와 Spring Framework 정리
26. 구현은 Setter를 통해 의존성을 전달받음 이때 의존성은 모두 Concrete Class가 아닌 Interface 기반임 외부 XML파일로 의존성 정의 Spring Bean Factory는 설정을 읽어 객체를 생성함 테스트 케이스 작성시 관심 없는 부분은 Mock처리하여 쉽게 작성할 수 있음 DI 예제 정리