Spring 上下文WebApplicationContext.是服务器启动的时候加载ContextLoaderListener 的时候存在 ServletContext 中

servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

可以通过WebApplicationContextUtils 获取

ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);    context 为ServletContext

可以通过继承ApplicationObjectSupport或者WebApplicationObjectSupport。用方法getApplicationContext(),Spring初始化时,会通过该抽象类的setApplicationContext(ApplicationContext context)方法将ApplicationContext 对象注入.

非B/S 系统获取

ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml");

ac.getBean("beanId");

这种方式适用于采用Spring框架的独立应用程序,需要程序通过配置文件手工初始化Spring的情况

Spring 上下文的更多相关文章

  1. 15.SpringMVC和Spring上下文关系(为什么SpringMVC可以调用到Spring)

    springmvc上下文继承于spring, 也就是springmvc的上下文可访问spring上下文,在springmvc的上下文中可取得spring bean. spring上下文是spring启 ...

  2. 基于Spring DM管理的Bundle获取Spring上下文对象及指定Bean对象

    在讲述服务注册与引用的随笔中,有提到context.getServiceReferences()方法,通过该方法可以获取到OSGI框架容器中的指定类型的服务引用,从而获取到对应的服务对象.同时该方法还 ...

  3. callable与runable区别?switch char ?sql只查是否存在,sql复制表 ?反射 ? spring mvc 和spring 上下文区别?

    中化技术部  2018.4.16 1. callable 和 thread 区别 实现Callable接口的线程能返回执行结果,而Runable 不可以 . Callable 的call方法允许抛出异 ...

  4. 五)Spring + Quartz 复杂业务的两个问题:获取Spring上下文 和 自动注入服务类

    配置如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  5. JAVA获取Spring上下文

    1. 添加监听 public class SpringContextListener implements ServletContextListener { //获取spring注入的bean对象 p ...

  6. Spring 上下文操作工具类 ContextUtils

    ContextUtils.java package com.java.config; import org.springframework.beans.BeansException; import o ...

  7. 获取spring上下文 - applicationContext

    前言 spring上下文是spring容器抽象的一种实现.将你需spring帮你管理的对象放入容器的一种对象,ApplicationContext是一维护Bean定义以及对象之间协作关第的高级接口. ...

  8. spring中的web上下文,spring上下文,springmvc上下文区别(超详细)

    web上下文(Servlet context),spring上下文(WebApplication Context),springmvc上下文(mlWebApplicationCont)之间区别. 上下 ...

  9. springMVC和spring上下文的关系

    springMVC继承了spring的servletcontext上下文, 所以, controller里的@Resource注入可以用以下替代 @Resource private IUserServ ...

随机推荐

  1. MySQL之外键约束

    MySQL之外键约束 MySQL有两种常用的引擎类型:MyISAM和InnoDB.目前只有InnoDB引擎类型支持外键约束.InnoDB中外键约束定义的语法如下: [CONSTRAINT [symbo ...

  2. 使用bootstrap做一个响应式的页面

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. jQuery.attributes源码分析(attr/prop/val/class)

    回顾 有了之前的几篇对于jQuery.attributes相关的研究,是时候分析jQuery.attr的源码了 Javascript中的attribute和property分析 attribute和p ...

  4. 初识JavaScript,感觉整个人都不好了。。。

    学习web前端的开发已经将近一个月了,开发中的三个大兄弟——“html”.“css”.“JavaScript”,小哥我已经深入接触了前两位,并与他俩建立的深厚的友谊.在编写过程中,不能说达到各位大神的 ...

  5. 关于js作用域

    我们知道在编程语言中,作用域的作用就是控制变量.参数的可见范围和生命周期. 同时内部函数也可访问外部的函数和变量. js中提供了函数作用域的功效,比如在函数中定义的变量外部是无法访问到的: funct ...

  6. CSS自学笔记(3):CSS选择器

    CSS中提供了非常丰富的选择器,但是由于浏览器的支持情况,很多选择器很少用到. 1.基础选择器 选择器 含义 示例 * 通用元素选择器,匹配任何元素 * { margin:0; padding:0; ...

  7. J2SE知识点摘记(二十)

    List 1.3.1        概述 前面我们讲述的Collection接口实际上并没有直接的实现类.而List是容器的一种,表示列表的意思.当我们不知道存储的数据有多少的情况,我们就可以使用Li ...

  8. SLC和MLC

    SLC 和MLC分别是是Single Layer Cell 单层单元和Multi-Level Cell多层单元的缩写,SLC的特点是成本高.容量小.速度快,而MLC的特点是容量大成本低,但是速度慢.M ...

  9. substr,substring,slice 的区别

    javascript中的三个函数substr,substring,slice都可以用来提取字符串的某一部分(函数名称都是小写,不要写成subStr,subString又或者Substring,记住js ...

  10. SPOJ GSS1 && GSS3 (无更新/更新单点,并询问区间最大连续和)

    http://www.spoj.com/problems/GSS1/ 题意:无更新询问区间最大连续和. 做法:线段树每个节点维护sum[rt],maxsum[rt],lsum[rt],rsum[rt] ...