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 ApplicationObjectSupportimplements ServletContextAware

从上面的继承关系看,获取Application Context还可以继承WebApplicationObjectSupport 、ApplicationObjectSupport,继承加强耦合性不推荐。

3、WebApplicationContextUtils工具类

ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());

4、从当前线程绑定获取(Spring boot不支持)

ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();

最新文章

  1. javascript序列化和反序列化
  2. 几个 Ceph 性能优化的新方法和思路(2015 SH Ceph Day 参后感)
  3. JS替换函数
  4. 编译 curl with ssl
  5. 基于Qt实现的截图小程序
  6. ectouch第七讲 之ECshop模板机制整理
  7. MongoDB C#驱动中Query几个方法 (转)
  8. 【M34】如何在同一个程序中结合C++和C
  9. 动态链接库找不到 : error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory
  10. 将yyyyMMdd HH:mm:ss格式的时间转换成时间类型
  11. Android导入项目时出现红色感叹号
  12. MySql按指定天数进行分组数据统计分析 2
  13. 与众不同 windows phone (23) - Device(设备)之硬件状态, 系统状态, 网络状态
  14. struts2教程&实例
  15. Ubuntu 16下安装64位谷歌Chrome浏览器
  16. (MariaDB/MySQL)之DML(2):数据更新、删除
  17. mongodb怎么创建数据库和配置用户
  18. Node.js(day4)
  19. nginx+apache动静分离/负载均衡
  20. 慕课网c#开发轻松入门6-8最终项目

热门文章

  1. struts2--上传总结(限制大小和类型 非法上传的跳转)
  2. 复利计算C语言转java的相关代码
  3. PHP 操作redis 详细讲解 转的 http://www.cnblogs.com/jackluo/p/3412670.html
  4. HTTP协议 结构,get post 区别(阿里面试)
  5. utuntu 安装python3.5
  6. Spring mvc 数据验证框架注解
  7. windows200364位iis6 php环境搭建
  8. Redis windows环境安装 以及 redis整合spring
  9. BZOJ4950 Wf2017Mission Improbable(二分图匹配)
  10. Contest 5