1. The IoC container

    1.1 Introduction to the Spring IoC container and beans

    • Inversion of Control (IOC)는 Dependency Injection (DI)로 알려져있음. 
      • 1) IoC는 객체가 dependency를 정의하는 절차임
        • 생성자의 인수, factory 메서드의 인수, 또는 객체가 생성된 후 set 메서드로 dependency를 정의할 수 있음
      • 2) 정의한 후, 컨테이너는 bean을 만들 때 dependency를 주입함
      • bean이 의존성/인스턴스화를 직접 다루는 것이 아니라 외부에서 다루고 있음. 제어가 역전된 것이기 때문에 Inversion of Control이라고 부름
        • 컨테이너가 의존성/인스턴스화를 다룰 때 클래스를 직접적으로 construct하거나, Service Locator와 같은 메커니즘을 사용함

     

    • Spring의 IoC 컨테이너의 기초는 org.springframework.beans, org.springframework.context 패키지에서 다루고 있음
      • BeanFactory Interface: 어느 타입의 객체도 다룰 수 있게 하는 고급 confinguration 메카니즘 제공
        • 쉽게 말해서, configuration 프레임워크와 기본적인 기능 제공
      • ApplicationContext: BeanFactory를 확장한 interface로 Spring AOP 기능, message resource handling, event 게시화, application-layer specific context (ex. WebApplicatonContext)을 더 쉽게 추가할 수 있음
        • BeanFactory에 enterprise-specific한 기능을 더한 것 

     

    • Bean: IoC 컨테이너가 관리하는 객체
      • Bean은 IoC 컨테이너에 의해 인스턴스화되고, 조립되고, 관리됨
      • Bean과 Bean들 사이의 종속성은 컨테이너가 사용하는 configuration metadata를 반영함

    1.2 Container Overview

    • ApplicationContext 인터페이스는 IoC 컨테이너를 나타냄
      • bean의 인스턴스화, 구성, 조립 등을 함
      • 컨테이너는 confinguration metadata를 읽음으로써 어떤 객체를 인스턴스화하고, 구성하고, 조립할지에 대한 instruction을 얻는다.
        • 이 메타데이터는 XML, java의 어노테이션, 또는 java code에 있다.

     

    • ApplicationContext의 여러 구현체들이 Spring과 함께 제공된다.
      • ClassPathXmlApplicationContext, FileSystemXmlApplicationContext 
      • XML이 configuration 메타데이터를 정의하는 전통적인 방식이었지만, 추가 메타데이터 형식을 선언적으로 지원할 수 있도록 소량의 XML cofiguration을 제공함. 따라서 java의 어노테이션 또는 code를 메타데이터 형식으로 사용하도록 컨테이너에 지시할 수 있음

     

    • 대부분의 경우, Spring IoC 컨테이너를 하나 이상 인스턴스화 하는 명시적인 코드가 필요하지 않음
      • 웹 응용 프로그램을 만드는 경우) web.xml 파일에 8줄 정도의 web descriptor XML이면 일반적으로 충분함

     

    • configuration metadat와 Application class가 합쳐져서 Spring Container(ApplicationContext)를 만듦. 그리고 ApplicationContext가 초기화된 후, 완전하게 구성되고 실행가능한 시스템을 만들 수 있음.

     

    1.2.1. Configuartion metadata

    •  

     

     

     

     

     


     

    Core Technologies

    In the scenario above, using @Autowired works well and provides the desired modularity, but determining exactly where the autowired bean definitions are declared is still somewhat ambiguous. For example, as a developer looking at ServiceConfig, how do you

    docs.spring.io

     

    '백엔드 > Spring' 카테고리의 다른 글

    Docker(도커)  (0) 2023.03.31
    5. Aspect Oriented Programming with Spring  (0) 2023.03.15
    JPA와 연관관계 (with MySQL) (1)  (0) 2022.10.20
    JWT 토큰을 이용한 로그인 구현 (1)  (0) 2022.10.13
    Spring Security 동작과정  (0) 2022.10.13

    댓글