记一次bean加载冲突

编程入门 行业动态 更新时间:2024-10-14 18:13:09

记一次bean<a href=https://www.elefans.com/category/jswz/34/1771433.html style=加载冲突"/>

记一次bean加载冲突

一个工具类引发的生产失效

以下代码为SpringUtils工具类,作用是可以在spring项目中引用已经加载的bean

import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import java.util.Map; /** * @author: yuyangkang * @Title: SpringUtil * @ProjectName: settle * @Description: * @date: 2021/7/25 18:20 */ @Component public class SpringUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) { SpringUtil.applicationContext = applicationContext; } public static <T> T getBean(String beanName) { if(applicationContext.containsBean(beanName)){ return (T) applicationContext.getBean(beanName); }else{ return null; } } public static <T> Map<String, T> getBeansOfType(Class<T> baseType){ return applicationContext.getBeansOfType(baseType); } }

更多推荐

记一次bean加载冲突

本文发布于:2024-03-06 09:19:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1714957.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   冲突   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!