加载冲突"/>
记一次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加载冲突
发布评论