com.github.ji4597056.utils.SpringUtils Maven / Gradle / Ivy
The newest version!
package com.github.ji4597056.utils;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* spring util
*
* @author Jeffrey
* @since 2017/7/6 17:08
*/
@Component
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext context;
public static ApplicationContext getApplicationContext() {
return context;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (context == null) {
context = applicationContext;
}
}
public static Object getBean(String name) {
return getApplicationContext().getBean(name);
}
public static T getBean(Class clazz) {
return getApplicationContext().getBean(clazz);
}
public static T getBean(String name, Class clazz) {
return getApplicationContext().getBean(name, clazz);
}
public static Map getBeanOfType(Class clazz) {
return getApplicationContext().getBeansOfType(clazz);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy