spring获取ApplicationContext
来源:互联网 发布:淘宝网网页版登录入口 编辑:程序博客网 时间:2024/05/14 10:49
方法一:在初始化时保存ApplicationContext对象
ApplicationContext ac =newFileSystemXmlApplicationContext("applicationContext.xml");
方法二:通过Spring提供的工具类获取ApplicationContext对象
ApplicationContext ac1 =WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc);
ApplicationContext ac2 =WebApplicationContextUtils.getWebApplicationContext(ServletContext sc);
ServletContext sc = request.getSession().getServletContext();方法三:继承自抽象类ApplicationObjectSupport
说明:抽象类ApplicationObjectSupport提供getApplicationContext()方法,可以方便的获取ApplicationContext。
Spring初始化时,会通过该抽象类的setApplicationContext(ApplicationContext context)方法将ApplicationContext 对象注入。
方法四:继承自抽象类WebApplicationObjectSupport
说明:类似上面方法,调用getWebApplicationContext()获取WebApplicationContext
方法五:实现接口ApplicationContextAware
说明:实现该接口的setApplicationContext(ApplicationContext context)方法,并保存ApplicationContext 对象。Spring初始化时,会通过该方法将ApplicationContext对象注入。
方法六:通过Spring提供的ContextLoader
WebApplicationContext wac =ContextLoader.getCurrentWebApplicationContext();
wac.getBean(beanID);
0 0
- Spring获取ApplicationContext
- spring获取ApplicationContext
- Spring MVC获取ApplicationContext
- 获取spring ApplicationContext
- spring 获取上下文applicationContext
- 怎么获取Spring的ApplicationContext
- 怎么获取Spring的ApplicationContext
- Spring +quartz获取ApplicationContext上下文
- spring 获取 ApplicationContext的方法
- Spring Bean获取applicationcontext方法
- Spring获取ApplicationContext的方法
- Spring,通过ApplicationContextAware获取ApplicationContext
- 获取Spring上下文即ApplicationContext
- JavaWeb中获取Spring的ApplicationContext
- 普通Java类获取Spring的ApplicationContext
- Spring获取bean方式(BeanFactory和ApplicationContext)
- spring获取ApplicationContext的方法-持续更新
- 普通Java类获取Spring的ApplicationContext
- ZZUOJ-10436: easy problem
- Sicily 图的广度优先搜索
- 网桥防火墙中Ebtables可以做的事
- 弹窗效果:TipsWindown
- Web Services 指南之:Web Services 的特性
- spring获取ApplicationContext
- Android Unit Test
- JVM垃圾回收描述
- .net Windows服务程序和安装程序制作
- 字符,字节和编码
- Android RecyclerView 使用完全解析 体验艺术般的控件
- 决策树
- 【实战】五个Docker监控工具的对比
- Gradle Plugin Samples 之 Gradle Build Variants(六)