package incheon.sgp.rst.util;


import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;


/**
 * Class Provider
 */
@Slf4j
@Component
@Lazy(false)
public class RstApplicationContextProvider implements ApplicationContextAware {
    
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext ctx) {
        applicationContext = ctx;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    // 제너릭 타입 메서드 - 빈 네임, 타입으로 가져오기
    public <T> T getBean(String beanName, Class<T> clazz) {
    	log.debug("beanName : {}", beanName);
        return applicationContext.getBean(beanName, clazz);
    }

    // 제너릭 타입 메서드 - 타입으로 가져오기
    public <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }
}