一、工具类
package net.jointflight.common.shiro.filter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @Author ***
* @Date 2022/1/8 16:25
* @Version 1.0
* @remark 系统未加载bean时获取bean
*/
@Component
public class SpringBeanFactoryUtils implements ApplicationContextAware {
private static ApplicationContext context = null;
//获取bean
public static <T> T getBean(Class<T> type) {
return context.getBean(type);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringBeanFactoryUtils.context == null) {
SpringBeanFactoryUtils.context = applicationContext;
}
}
}
@Autowired
private RedisUtil redisUtil;
//手动获取Bean对象
redisUtil = SpringBeanFactoryUtils.getBean(RedisUtil.class);