获取Spring的ApplicationContext的几种方式
转载自 获取Spring的ApplicationContext的几种方式
Application Context定义
简单来说就是Spring中的高级容器,可以获取容器中的各种bean组件,注册监听事件,加载资源文件等功能。
具体定义可以参考官网:https://spring.io/understanding/application-context
Understanding Application Context
The ApplicationContext
is the central interface within a Spring application for providing configuration information to the application. It is read-only at run time, but can be reloaded if necessary and supported by the application. A number of classes implement the ApplicationContext
interface, allowing for a variety of configuration options and types of applications.
The ApplicationContext
provides:
Bean factory methods for accessing application components.
The ability to load file resources in a generic fashion.
The ability to publish events to registered listeners.
The ability to resolve messages to support internationalization.
Inheritance from a parent context.
Application Context获取的几种方式
1、直接注入
@Resource
private ApplicationContext ctx;
2、实现ApplicationContextAware接口(推荐)
WebApplicationObjectSupport extends ApplicationObjectSupport implements ServletContextAware
从上面的继承关系看,获取Application Context还可以继承WebApplicationObjectSupport 、ApplicationObjectSupport,继承加强耦合性不推荐。
3、WebApplicationContextUtils工具类
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
4、从当前线程绑定获取(Spring boot不支持)
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
获取Spring的ApplicationContext的几种方式相关推荐
- jdbc Template 介绍和 spring 链接数据源的四种方式
为什么具体讲template介绍和spring jdbc链接数据源的几种方式放在一起介绍,在于你在使用template的时候,具体配置数据源,或者在链接配置数据源的时候要是使用template,就在在 ...
- Spring属性注入的三种方式(超详细)
属性注入的三种方式 使用set方法进行注入 使用有参构造函数进行注入 使用p名称空间注入 首先了解下面两个名词的含义: IOC:控制反转(Inversion of Control,缩写为IoC),是面 ...
- Spring循环依赖的三种方式以及解决办法
Spring循环依赖的三种方式以及解决办法 [转]https://www.cnblogs.com/liuqing576598117/p/11227007.html 示例 https://github. ...
- Spring实现AOP的4种方式
Spring实现AOP的4种方式 先了解AOP的相关术语: 1.通知(Advice): 通知定义了切面是什么以及何时使用.描述了切面要完成的工作和何时需要执行这个工作. 2.连接点(Joinpoint ...
- Spring事务配置的五种方式 说明
Spring事务配置的五种方式 [转 http://blog.csdn.net/hjm4702192/article/details/17277669] Spring配置文件中关于事务配置总是由三个 ...
- spring配置属性的两种方式
spring配置属性有两种方式,第一种方式通过context命名空间中的property-placeholder标签 <context:property-placeholder location ...
- Spring创建Bean的三种方式的使用和区别
在学习Spring的时候,发现Spring的IOC(控制反转)为我们提供的三种创建Bean的方式. 1.Spring创建Bean的三种方式 这里采用XML配置,分别演示三种创建Bean的方式和代码. ...
- Spring创建Bean的3种方式
1. Spring创建Bean的三种方式 1. 调用构造器(因为常用就不讲) 2. 调用静态工厂方法 3. 调用实例工厂方法 2. 使用静态工厂方法 1.此时<bean.../>元素要指定 ...
- 【REACT NATIVE 系列教程之十三】利用LISTVIEW与TEXTINPUT制作聊天/对话框获取组件实例常用的两种方式...
本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/react-native/2346.html ...
最新文章
- 【.NET开发之美】如何提高.NET DataMap中的加载速度
- boost::mpl模块实现range_c相关的测试程序
- 学习《apache源代码全景分析》之多任务并发处理摘录
- AT2070-[ARC061D]3人でカードゲーム/Card Game for Three【计数,组合数学】
- 一次性搞懂JavaScript正则表达式之语法
- node函数 node路由
- javascript对象序列化(对象与JSON字符串的互换)
- Remove Middle Man
- ]MySQL操作命令语句实例
- 毕业照还可以这样玩()
- Mybatis框架的介绍以及详细使用,结合JDBC讲解,有利于对mybatis的注解和配置文件的理解,结合我上一篇文章,更好容易理解,通俗易懂,适合刚接触框架的新手(二)
- 塞班系统 微信 服务器忙,微信QQ遭停用,塞班系统部分机型彻底不能登陆
- GoLang笔记—容器篇
- 表贴电阻尺寸与什么有关_贴片电阻、贴片电容规格、封装、尺寸、功率(转)
- layui数据表格实现内容筛选的全选和反选功能
- 支持向量机检测DGA
- java基于springboot畜牧场信息管理系统
- 智能工厂建设整体解决方案
- 百度飞桨—PM2.5预测
- 电子行业求职,技术才是硬道理
热门文章
- 集合的定义与并查操作(C语言)
- php fpm 调试模式,调试 – nginx php-fpm xdebug netbeans只能启动一个调试会话
- linux启动mqtt_linux下安装MQTT服务器 - EMQTT
- exceptionhandler注解_SpringMVC 中 @ControllerAdvice 注解的三种使用场景!
- Codeforces Round #727 (Div. 2) F. Strange Array 线段树 + 区间合并 + 排序优化
- 【CF1311E】Construct the Binary Tree【增量构造】【复杂度证明】
- bzoj5093: [Lydsy1711月赛]图的价值
- cf600 E. Lomsat gelral
- Mod, Or and Everything HDU - 6950
- 数论分块练习([CF830 C]Bamboo Partition + [hdu 6395]Sequence )