1 / 50

SPRING REFERENCE CHAPTER 3. THE IOC CONTAINER

SPRING REFERENCE CHAPTER 3. THE IOC CONTAINER. 백기선. Index. 1. Introduction 2. Basics – containers and beans 3. Dependencies 4. Bean scopes 5. Customizing the nature of a bean 6. Bean definition inheritance 7. Container extension points 8. The ApplicationContext

ardice
Download Presentation

SPRING REFERENCE CHAPTER 3. THE IOC CONTAINER

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SPRING REFERENCE CHAPTER 3. THE IOC CONTAINER 백기선

  2. Index • 1. Introduction • 2. Basics – containers and beans • 3. Dependencies • 4. Bean scopes • 5. Customizing the nature of a bean • 6. Bean definition inheritance • 7. Container extension points • 8. The ApplicationContext • 9. Glue code and the evil singleton

  3. 1. Introduction

  4. IoC • Inversion of Control • http://younghoe.info/128 • IoC Container • BeanFactory • ApplicationContext • http://whiteship.tistory.com/518

  5. 2. Basics – containers and beans

  6. Containers • Container • BeanFactory • ApplicationContext • Configuration Metadata • XML • JavaConfig

  7. 예제 1(simple configuration) • XML based Configuration metadata • Using Container • ApplicationContext context = new ClassPathXmlApplicationContext(new String []{"beanConfiguration.xml"}); • Member member = (Member)context.getBean(“member”);

  8. Beans • Naming beans • id, name, alias • BeanDefinition Name • Aliasing 주의할 것 • 빈(bean)의 이름 지정Spring의 naming/aliasing 정책에 대한 수사 (상)Spring의 naming/aliasing 정책에 대한 수사 (중)Spring의 naming/aliasing 정책에 대한 수사 (하) • Aliasing Beans (4)복잡한 Alias

  9. Instantiation Bean • 생성자 • <bean id="혜인" name="이쁘니" class="beanConfiguration.Member"/> • getBean(“혜인”); • 팩토리 • Static • <bean id="pizza" class="keesun.PizzaStore" factory-method="createPizza"/> • Instant • <bean id="pizzaStore" class="keesun.pizzaStrore" /><bean id="pizza" factory-bean="pizzaStore" factory-method="createPizza" /> • getBean(“pizza”); • FactoryBean

  10. 예제2(wrong aliasing)

  11. 3. Dependencies

  12. Injection • Constructor-Injection • Setter-Injection • Method-Injection

  13. 예제3(DI)

  14. Constructor Argument Resolution • 생성자의 인자 구별하기 • 세터의 인자는 구별할 필요가 없나? • type • index

  15. 예제4(constructor-arg 구별)

  16. <property /> <constructor-arg /> • 종속성을 가지는 대상에 따라 사용할 수 있는 하위 태그들이 여러개 있습니다. • <value /> <idref /> <ref /> <bean /><list /> <set /> <map /> <props /> <null /> • idref 엘리먼트Inner beansCollections - <list />Collection Merging

  17. <bean /> • depend-on=“빈 이름들” • lazy-init="true“ • autowire=“no | byName | byType | constructor | autodetect” • dependency-check=“none | simple | object | all ”

  18. 예제5(auto-wring)

  19. 4. Bean scopes

  20. scopes

  21. singleton

  22. prototype

  23. 예제6(singleton)

  24. 예제7(prototype)

  25. 잠시만 쉬었다 할까요?

  26. 5. Customizing the nature of a bean

  27. InitializingBean & DisposableBean

  28. init-method & destroy-method

  29. 예제8(customizing)

  30. Knowing who you are • BeanFactoryAware 인터페이스 구현하기 • BeanFactoryAware 사용 예 • ObjectFactoryCreatingFactoryBean 사용하기 • ObjectFactoryCreatingFactoryBean 사용 예

  31. 예제9(ticket)

  32. 6. Bean definition inheritance

  33. Bean 설정 상속 • 부모 • abstract=“true” 설정한 bean은 생성 할 수 없다. • class 속성에 값이 없으면 반드시abstract=“true”. • 자식 • parent 속성에 부모 bean 이름.

  34. 예제10(빈 설정 상속)

  35. 7. Container extension points

  36. BeanPostProcessors BeanPostProcessor 사용 예

  37. BeanFactoryPostProcessors • BeanPostProcessor와 비슷하지만 적용되는 대상이 Configuration Metadata 입니다. • bean을 만들고 DI하기 전에 설정 내용을 변경할 수 있습니다. • BeanFactoryPostProcessor 사용 예

  38. 여기서 잠깐 • ApplicationContext와 BeanFactory 차이점 • ApplicationContext 는 그냥 bean으로 등록 해두면 알아서 찾아서 처리해줌. • BeanFactory는 별도의 등록 절차가 필요함.

  39. FactoryBean • 여기서 질문 • 지금까지 본 예제 들 중에 FactoryBean을 사용한 곳은 어디인가요? • '만들 수 없는 것'을 FactoryBean으로 만들기

  40. FactoryBean IoC Container FactoryBean

  41. FactoryBean FactoryBean getBean(“car”); ApplicationContext getObject(); CarFactoryBean named by “car”

  42. 8. The ApplicationContext

  43. MessageSource • ResourceBundleMessageSource 클래스 • JDK의 ResourceBundle 클래스와 MessageFormat 클래스를 기반으로 만들었으며, 번들에 특정 이름으로 접근할 수 있는 클래스입니다. • ReloadableResourceBundleMessageSource 클래스 • JVM 실행 도중 번들을 다시 읽어 들이는 것이 가능합니다.

  44. 개발자 라며?

  45. Container 라며? • ApplicationContext가 하는 일이 뭐지? Container라며? • 빈 name 중에 messageSource 인 빈이 있으면 읽어 들여서 MessageSource 일도 한단다. • Container라며? • 이벤트를 발생 시키길 원할 땐 ctx.publishEvent(evt); 이런식으로 이벤트도 발생시켜 준단다. • Container라며? • 사실 난 ResouceLoader이기도 하단다. 대엽씨가 이따가 알려줄꺼야. • Container라며? • 다 용도 컨테이너라고 할 수 있지…

  46. 예제11(MessageSource)

  47. 마지막 예제-Event

  48. 마지막 예제 – Event Listener

  49. 마지막 예제 – Event Publisher

  50. 마지막 예제 – Configuration & Run

More Related