아무거나

[spring] DI(Dependency Injection) - 2 본문

Java & Kotlin/Spring

[spring] DI(Dependency Injection) - 2

전봉근 2019. 12. 25. 23:02
반응형

[spring] DI(Dependency Injection) - 2

 

1. 스프링 컨테이너의 이해

package com.javalec.ex;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class MainClass {
    public static void main(String[] args) {
        String configLocation = "classpath:applicationCTX.xml";
        AbstractApplicationContext ctx = new GenericXmlApplicationContext(configLocation);  // 스프링 컨테이너 생성(Ioc)
        MyInfo myInfo = ctx.getBean("myInfo", MyInfo.class); // 스프링 컨테이너에서 컴포넌트 가져옴
        myInfo.getInfo();
        ctx.close();
    }
}​ 

 

 

참고: https://www.inflearn.com/course/%EC%9E%90%EB%B0%94-%EC%8A%A4%ED%94%84%EB%A7%81-%EA%B0%95%EC%A2%8C/dashboard

반응형
Comments