package com.alibaba.ewtp.domain.psp.config; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; /** * @author baiyicanggou * @date 2021/7/19 7:57 下午 */ @Component public class SpringHelper implements ApplicationContextAware { private static ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContextParam) throws BeansException { applicationContext = applicationContextParam; } public static <T> T getBean(Class<T> tClass) { return applicationContext.getBean(tClass); } public static <T> T getBean(String name) { return (T)applicationContext.getBean(name); } public static <T> T getBean(String name, Class<T> tClass) { return applicationContext.getBean(name, tClass); } }