spring工程中得到注入bean的集中方式
来源:互联网 发布:大数据的四大特征 编辑:程序博客网 时间:2024/05/21 10:06
1、该方法不适用于获取注入的bean,没有解决(用注入方式注入的bean)
public class SpringApplicationContextUtil implements ApplicationContextAware{
public static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
SpringApplicationContextUtil.applicationContext=applicationContext;
}
public static Object getBean(String name){
return applicationContext.getBean(name);
}
}
2、
public class SpringUnitl {
public static <T> T getBean(String beanName){
WebApplicationContext web = ContextLoader.getCurrentWebApplicationContext();
return (T)web.getBean(beanName);
}
}
3、
public class SpringUnitl implements BeanFactoryPostProcessor {
private static ConfigurableListableBeanFactory beanFactory;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
SpringUnitl.beanFactory = beanFactory;
}
public static BeanFactory getBeanFactory() {
return beanFactory;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException {
return (T) beanFactory.getBean(name);
}
}
public class SpringApplicationContextUtil implements ApplicationContextAware{
public static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
SpringApplicationContextUtil.applicationContext=applicationContext;
}
public static Object getBean(String name){
return applicationContext.getBean(name);
}
}
2、
public class SpringUnitl {
public static <T> T getBean(String beanName){
WebApplicationContext web = ContextLoader.getCurrentWebApplicationContext();
return (T)web.getBean(beanName);
}
}
3、
public class SpringUnitl implements BeanFactoryPostProcessor {
private static ConfigurableListableBeanFactory beanFactory;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
SpringUnitl.beanFactory = beanFactory;
}
public static BeanFactory getBeanFactory() {
return beanFactory;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException {
return (T) beanFactory.getBean(name);
}
}
0 0
- spring工程中得到注入bean的集中方式
- spring工程中,不通过注入的方式获取bean
- spring 的集中注入方式
- Spring中bean的注入方式
- Spring的bean注入方式
- spring bean注入的方式
- spring的配置文件中bean的注入方式
- spring的配置文件中bean的注入方式
- spring中bean的注入方式的选择?
- spring中bean的注入方式的选择?
- Spring中Bean属性为集合的注入方式
- Spring中bean的注入
- Spring bean注入方式
- spring ioc容器注入的集中方式,以及属性注入的集中依赖,继承,使用SPEL表达式,ioc容器的生命周期,bean的几种工厂方法配置方式,bean的自动装配
- Spring注入Bean的几种方式
- Spring bean的三种注入方式
- 在filter注入或者是得到spring托管的bean
- web 工程中利用Spring的 ApplicationContextAware接口自动注入bean
- Light OJ-----1336数论-----整数拆分推论
- MyBatis 批量插入数据
- 安装phantomjs,使用java代码进行截图
- FileOutputStream,OutputStreamWriter, BufferedWriter为什么连用?
- css空箭头的样式
- spring工程中得到注入bean的集中方式
- Copy List with Random Pointer
- brew 安装
- java 字符串系列化及反系列化 (未测试)
- Problem I : Palindrome Partitioning I
- Python 学习笔记二 函数、模块和对象
- 【HDU】1709 - The Balance(母函数)
- zabbix-agent key属性列表
- org.springframework.web.context.ContextLoaderListener