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();

获取Spring的ApplicationContext的几种方式的更多相关文章

  1. Java代码获取spring 容器的bean几种方式

    一.目的 写了一个项目,多个module,然后想在A模块中实现固定的config注入,当B模块引用A时候,能够直接填写相对应的配置信息就行了.但是遇到一个问题,B引用A时候,A的配置信息总是填充不了, ...

  2. 获取spring的ApplicationContext几种方式【转】

    转自:http://blog.sina.com.cn/s/blog_9c7ba64d0101evar.html Java类获取spring 容器的bean 常用的5种获取spring 中bean的方式 ...

  3. Spring创建JobDetail的两种方式

    一.Spring创建JobDetail的两种方式 二.整合方式一示例步骤 1.将spring核心jar包.quartz.jar和Spring-context-support.jar导入类路径. 2.编 ...

  4. Spring 循环依赖的三种方式(三级缓存解决Set循环依赖问题)

    本篇文章解决以下问题: [1] . Spring循环依赖指的是什么? [2] . Spring能解决哪种情况的循环依赖?不能解决哪种情况? [3] . Spring能解决的循环依赖原理(三级缓存) 一 ...

  5. spring配置属性的两种方式

    spring配置属性有两种方式,第一种方式通过context命名空间中的property-placeholder标签 <context:property-placeholder location ...

  6. Spring实现AOP的4种方式(转)

    转自:http://blog.csdn.net/udbnny/article/details/5870076 Spring实现AOP的4种方式 先了解AOP的相关术语:1.通知(Advice):通知定 ...

  7. Spring 使用AspectJ的三种方式

    Spring 使用AspectJ 的三种方式 一,使用JavaConfig 二,使用注解隐式配置 三,使用XML 配置 背景知识: 注意 使用AspectJ 的 时候 要导入相应的Jar 包 嗯 昨天 ...

  8. 运行 Spring Boot 应用的 3 种方式

    今天介绍 3 种运行 Spring Boot 应用的方式,看大家用过几种? 你所需具备的基础 什么是 Spring Boot? Spring Boot 核心配置文件详解 Spring Boot 开启的 ...

  9. Spring事务管理的四种方式(以银行转账为例)

    Spring事务管理的四种方式(以银行转账为例) 一.事务的作用 将若干的数据库操作作为一个整体控制,一起成功或一起失败.   原子性:指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不 ...

随机推荐

  1. 周总结<3>

    经过了一周的学习,我们在html以及C语言方面又有的新的知识点的学习,包括计算机导论也学会了路由器的设置. html 鼠标事件 C 二叉树的遍历代码 计算机导论 路由器的设置 Html案例: < ...

  2. Spring的初始化:org.springframework.web.context.ContextLoaderListener

    在web.xml中配置 <listener>    <listener-class>org.springframework.web.context.ContextLoaderL ...

  3. 对IT行业的一些思考

          阅读完两篇报道,从“2014年十大最热门行业和职业排行榜”可以看出最热门的行业是IT行业,可以看出IT行业在未来的发展前景很乐观,选择IT行业的人也会越来越多,IT行业也会越来越庞大.但是 ...

  4. [2017BUAA软工]第三次博客作业:案例分析

    第三次博客作业:案例分析 1. 调研和评测 1.1 BUG及设计缺陷描述 主要测试博客园在手机端上的使用情况. [BUG 01] 不能后退到上一界面(IOS) 重现步骤:打开博客首页中任意博文,点击博 ...

  5. PAT 甲级 1077 Kuchiguse

    https://pintia.cn/problem-sets/994805342720868352/problems/994805390896644096 The Japanese language ...

  6. web移动开发最佳实践之js篇

    一.js概述 js即JavaScript,是被设计用来验证表单.检测浏览器.创建cookies.改进设计以及更多应用的网络脚本语言,它非常容易使用.在web应用中,它是主要的编程语言,主要用途是进行各 ...

  7. SSH管理(重启 停止 运行 安装)centos7

    下面整理经常用到管理SSH服务的命令,方便复制哈. SSH服务状态 systemctl status sshd.service SSH运行命令 service sshd start SSH重启命令 s ...

  8. 【开发工具IDE】Eclipse相关配置

    1. 修改workspace编码为UTF-8 1.1. 修改jsp编码为UTF-8 2. 修改字体 3. 添加系统中的JDK 4. 导入formatter模板 5. 修改maven配置文件 打开文件: ...

  9. Unbuntu+nginx+mysql+php

    1/准备 sudo su --切换到root 2/nginx安装 apt-get update apt-get install nginx 3/mysql 安装 apt-get install mys ...

  10. js复选框插件

    <div class="selectList selectQgClass" id="selectQgClass"> <div class=&q ...