获取spring容器,以访问容器中定义的其他bean
来源:互联网 发布:网络约车平台 计划书 编辑:程序博客网 时间:2024/06/04 19:32
package com.ihappylife.spring.context;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* 获取spring容器,以访问容器中定义的其他bean
*/
public class SpringContextUtil implements ApplicationContextAware {
// Spring应用上下文环境
private static ApplicationContext applicationContext;
/**
* 实现ApplicationContextAware接口的回调方法,设置上下文环境
*/
public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {
SpringContextUtil.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
/**
* 获取对象
* 这里重写了bean方法,起主要作用
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws BeansException
*/
public static Object getBean(String beanId) throws BeansException {
if(applicationContext==null){
applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext-*.xml");
}
return applicationContext.getBean(beanId);
}
}
- 获取spring容器,以访问容器中定义的其他bean
- 获取spring容器,以访问容器中定义的其他bean
- 获取Spring 容器中bean的方法
- 获取spring容器中bean的方法
- Web容器中获取spring容器的bean对象
- Bean获取Spring容器
- Bean获取Spring容器
- Servlet中访问spring容器管理的bean
- 从spring容器中获取bean
- Spring动态获取IoC容器中管理的Bean
- Spring线程获取容器中bean的方法
- 从Spring容器中获取bean的几种方式
- 获取Spring容器中Bean的工具类
- 在web容器中获取spring容器中的bean对象
- 配置springmvc在其他类中(spring容器外)获取注入bean
- 【Spring】Spring容器获取Bean
- java类获取spring容器的bean
- Java类获取spring 容器的bean
- JavaBean对象转map
- MetaQ技术内幕——源码分析 (地址)
- 内存分配管理
- Android中logcat和adb使用
- Cocos2d-x能够实现的效果总结
- 获取spring容器,以访问容器中定义的其他bean
- Lowest Bit
- Struts2的插件机制
- java 反射
- Unable to find a team with the given Team ID 问题解决方法
- [Dubbo实战]dubbo + zookeeper + spring 实战
- [网狐]6603后台最高管理员密码修改
- Android WebView 因重定向无法正常goBack()解决方案
- poj- 2002-Squares-哈希|除法散列法