spring 如何取的IOC容器得到里面的对象进行操作
来源:互联网 发布:godaddy 域名证书生成 编辑:程序博客网 时间:2024/06/05 19:04
import java.util.HashMap;import java.util.Map;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * spring工具类 * * */public class SpringUtil {private static ApplicationContext applicationContext=null;public static final String SCOPE_REQUEST = "requestContextHolder";public static final String SCOPE_SESSION = "sessionContextHolder";public static final String SCOPE_APPLICATION = "applicationContextHolder";@SuppressWarnings("rawtypes")private static Map contexts = new HashMap();@SuppressWarnings("static-access")public Object get(String key) {return this.contexts.get(key);}@SuppressWarnings({ "unchecked", "static-access" })public void put(String key, Object value) {this.contexts.put(key, value);}@SuppressWarnings("static-access")public void clear() {this.contexts.clear();}public static ApplicationContext getApplicationContext() {if (applicationContext == null) {applicationContext = new ClassPathXmlApplicationContext("classpath:mvc-config.xml","classpath:beans-config.xml");//配置文件路径setApplicationContext(applicationContext);}return applicationContext;}public static void setApplicationContext(ApplicationContext context) {applicationContext = context;}/** * 根据beanId取得实例 * * @param <T> * @param beanId * @return */@SuppressWarnings("unchecked")public static <T> T getBean(String beanId) {return (T) getApplicationContext().getBean(beanId);}@SuppressWarnings("unchecked")public static void put(String key, Object value, String scopeBeanId) {contexts = getBean(scopeBeanId);if (contexts != null)contexts.put(key, value);}@SuppressWarnings("unchecked")public static <T> T get(String key, String scopeBeanId) {contexts = getBean(scopeBeanId);if (contexts != null)return (T) contexts.get(key);return null;}public static void clear(String scopeBeanId) {contexts = getBean(scopeBeanId);if (contexts != null)contexts.clear();}}
0 0
- spring 如何取的IOC容器得到里面的对象进行操作
- 如何得到Spring 容器对象
- spring里面怎么取容器里面的常量值
- spring的Ioc容器
- Spring的IoC容器
- spring的IOC容器
- Spring 的IOC 容器
- spring非IOC容器中的对象获取IOC容器中对象的方法
- 普通java类如何取得注入spring Ioc容器的对象
- 普通java类如何取得注入spring Ioc容器的对象
- Filter中访问spring ioc容器中的对象的方式
- 方便获取Spring IOC容器中对象的工具类
- spring IOC容器创建对象的三种方式
- Spring的核心之IoC容器创建对象
- spring的IOC容器比New对象究竟好在哪
- 模仿spring的IOC容器
- Spring 的 IOC 容器讲解
- Spring IOC容器的实现
- Google play 提交app
- WMV播放代码的各项参数取值介绍
- Activity的启动模式以及onNewIntent(Intent intent)
- jquery实现菜单栏选择效果
- elipse如何退出调试模式
- spring 如何取的IOC容器得到里面的对象进行操作
- 软件测试用例的编写技巧
- android 学习笔记 解析json格式的数据 JSONObject 和GSON解析json格式数据
- 数据结构 时间复杂度 空间复杂度 一看就懂版本
- 基础
- 约瑟夫问题 java代码
- MySql数据库插入乱码
- [经验总结]--关于socket通信传输非char型数组的解决方法
- JAVA对DataSet的操作大集合