springMVC bean
程序员文章站
2022-07-11 14:22:43
...
springutil通用方法,用来获取单个bean对象。
package com.crfeb.tbmpt.commons.scan; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationEvent; import org.springframework.stereotype.Component; /** * @author:wbb * @date:2017-1-09 11:12 */ @Component public class SpringUtils implements ApplicationContextAware { private static ApplicationContext context; private SpringUtils() {} public void setApplicationContext(ApplicationContext context) throws BeansException { SpringUtils.context = context; } public static <T> T getBean(Class<T> clazz){ if (clazz == null) return null; return context.getBean(clazz); } public static <T> T getBean(String beanName, Class<T> clazz) { if (null == beanName || "".equals(beanName.trim())) { return null; } if (clazz == null) return null; return (T) context.getBean(beanName, clazz); } public static ApplicationContext getContext(){ if (context == null) return null; return context; } public static void publishEvent(ApplicationEvent event) { if (context == null) return; context.publishEvent(event); } }
上一篇: 站长推广思路 seo推广
推荐阅读
-
SpringMVC参数绑定学习总结【前后端数据参数传递】
-
springMVC_02hello案例
-
SpringMVC--RequestMapping
-
springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.example.service.HrService' avai
-
Spring在代码中获取bean的几种方式详解
-
02Spring基于xml的IOC配置--实例化Bean的三种方式
-
springmvc Controller详解
-
Spring 的 Bean 生命周期,11 张高清流程图及代码,深度解析
-
Spring 学习指南 第三章 bean的配置 (未完结)
-
Spring中bean对象的生命周期