手动获取spring的application和bean属性
来源:互联网 发布:威联通nas网络存储 编辑:程序博客网 时间:2024/05/22 06:23
import
java.util.Map;
import
org.springframework.beans.BeansException;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.ApplicationContextAware;
/**
* 获取ApplicationContext和Object的工具类
* @author wjq
*
*/
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
class
SpringContextUtils
implements
ApplicationContextAware {
private
static
ApplicationContext applicationContext;
public
void
setApplicationContext(ApplicationContext arg0)
throws
BeansException {
applicationContext = arg0;
}
/**
* 获取applicationContext对象
* @return
*/
public
static
ApplicationContext getApplicationContext(){
return
applicationContext;
}
/**
* 根据bean的id来查找对象
* @param id
* @return
*/
public
static
Object getBeanById(String id){
return
applicationContext.getBean(id);
}
/**
* 根据bean的class来查找对象
* @param c
* @return
*/
public
static
Object getBeanByClass(Class c){
return
applicationContext.getBean(c);
}
/**
* 根据bean的class来查找所有的对象(包括子类)
* @param c
* @return
*/
public
static
Map getBeansByClass(Class c){
return
applicationContext.getBeansOfType(c);
}
}
1
ApplicationContext ac =
new
FileSystemXmlApplicationContext(
"applicationContext.xml"
)
可选的操作方法有:
1
2
3
4
5
6
7
8
9
10
11
一:
String[] path={
"WebRoot/WEB-INF/applicationContext.xml"
,
"WebRoot/WEB-INF/applicationContext_task.xml"
};
ApplicationContext context =
new
FileSystemXmlApplicationContext(path);
二:
String path=
"WebRoot/WEB-INF/applicationContext*.xml"
;
ApplicationContext context =
new
FileSystemXmlApplicationContext(path);
三:
ApplicationContext ctx =
new
FileSystemXmlApplicationContext(
"classpath:地址"
);
阅读全文
0 0
- 手动获取spring的application和bean属性
- 手动获取spring的ApplicationContext和bean对象
- 手动获取spring的ApplicationContext和bean对象
- 手动获取Spring上下文和Bean对象
- servlet中手动获取spring的bean
- Spring手动获取指定Bean
- spring手动注册bean,移除bean,获取bean
- 使用spring配置C3P0连接池 并通过手动获取spring的ApplicationContext和bean对象使用库连接。
- 使用spring配置C3P0连接池 并通过手动获取spring的ApplicationContext和bean对象使用库连接
- 手动从spring WebApplicationContext 获取bean (一)
- 手动从spring BeanFactory 获取bean (二)
- spring源码(11)bean的parent属性详解和获取RootBeanDefinition
- Spring学习之获取其他Bean的属性值(PropertyPathFactoryBean)
- bean标签的属性和spring属性注入
- Spring中ApplicationContextAware实现获取bean的工具类,在servlet中通过servletContext获取application
- spring中通过ApplicationContext获取bean和通过bean工厂获取bean的区别
- 关于spring 的一些常见中手动获取bean 的 操作
- spring使用手动装载依赖的bean
- 最常用的消除浮动的方法
- 前端安装
- Java 面向对象编程概念
- bzoj3172 [Tjoi2013]单词(SA+暴力,类似bzoj2754)
- 股谚:会买是徒弟会卖才是师傅 学会这3种万能卖出法再不用愁
- 手动获取spring的application和bean属性
- Java琐碎知识整理
- Bmob后端云上传多张图片
- POJ 1523 SPF(割点所割连通分量数)
- Eclipse搭建Spring应用
- POJ 1236 Network of Schools [强连通分量]
- 机器学习实战K-近邻算法遇到的几个错误
- 【51Nod1201】整数划分
- iOS UITapGestureRecognizer区分单击和双击