@Component public class SpringContextUtil implements BeanFactoryAware { private static BeanFactory beanFactory; private final static Logger LOG = LoggerFactory.getLogger(SpringContextUtil.class); @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { SpringContextUtil.beanFactory = beanFactory; } public static <T> T getBean(String beanName) { if (null != beanFactory) { return (T) beanFactory.getBean(beanName); } return null; } }
spring获取bean(自定义工具类)
最新推荐文章于 2023-02-02 21:03:00 发布