io.github.novareseller.boot.utils.SpringUtils Maven / Gradle / Ivy
package io.github.novareseller.boot.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
* spring获取bean工具类
*
* @author 作者 Bowen
* @version 创建时间:2018年3月20日 下午10:13:18 类说明
*
*/
@Component
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringUtils.applicationContext = applicationContext;
}
public static T getBean(Class cla) {
return applicationContext.getBean(cla);
}
public static T getBean(String name, Class cal) {
return applicationContext.getBean(name, cal);
}
public static String getProperty(String key) {
return applicationContext.getBean(Environment.class).getProperty(key);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy