package com.arms.config; import lombok.Getter; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @Component public class ApplicationContextProvider implements ApplicationContextAware { @Getter private static final ApplicationContextWrapper applicationContextWrapper = new ApplicationContextWrapper(); @Override public void setApplicationContext(ApplicationContext ctx) throws BeansException { applicationContextWrapper.setApplicationContext(ctx); } public static T getBean(Class t){ return applicationContextWrapper.getBean(t); } private static class ApplicationContextWrapper{ private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext){ this.applicationContext = applicationContext; } public T getBean(Class t){ return applicationContext.getBean(t); } } }