主要用于从application中获取bean

1、applicationContext

在web.xml中使用listener配置

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

使用WebApplicationContext获取

WebApplicationContext webApplicationContext =ContextLoader.getCurrentWebApplicationContext();  




2、springMVC-serlvet

在web.xml中使用servlet配置

<servlet>

<servlet-name>springMVC</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:springMVC-servlet.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>springMVC</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

使用ServletContext获取

ServletContext servletContext=request.getSession().getServletContext();

WebApplicationContext webApplicationContext = (WebApplicationContext)servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

参考:springMVC 使用WebApplicationContext获取ApplicationContext对象

springMVC 使用WebApplicationContext获取ApplicationContext对象的更多相关文章

  1. 获取applicationContext对象的方法

    方法一:在初始化时保存ApplicationContext对象 代码: ApplicationContext ac = new FileSystemXmlApplicationContext(&quo ...

  2. spring获取ApplicationContext对象的方法——ApplicationContextAware

    一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...

  3. SpringBoot项目中获取applicationContext对象

    ApplicationContext 对象是Spring开源框架的上下文对象实例,也就是我们常说的Spring容器,一般情况下我们是不用手动来管理它,而是由Spring框架自己来维护bean之间的关系 ...

  4. 在Spring应用中创建全局获取ApplicationContext对象

    在Spring应用中创建全局获取ApplicationContext对象 1.需要创建一个类,实现接口ApplicationContextAware的setApplicationContext方法. ...

  5. spring中获取ApplicationContext对象的技巧,含源码说明

    第一步,实现接口ApplicationContextAware,重写setApplicationContext方法,下方代码标红的地方,绿色部分 可以通过声明来进行存储到本类中. @Component ...

  6. 如何获取SpringBoot项目的applicationContext对象

    ApplicationContext对象是Spring开源框架的上下文对象实例,在项目运行时自动装载Handler内的所有信息到内存.传统的获取方式有很多种,不过随着Spring版本的不断迭代,官方也 ...

  7. Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式

    转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236  Spring获取ApplicationContex ...

  8. spring中获取applicationContext

    常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...

  9. 获取SpringBean对象工具类

    获取SpringBean工具类 SpringBeanUtil代码如下: package com.meeno.wzq.util; import org.springframework.beans.Bea ...

随机推荐

  1. Click to add to Favorites Troubleshooting: High Version Count Issues (Doc ID 296377.1)

    Copyright (c) 2018, Oracle. All rights reserved. Oracle Confidential. Click to add to Favorites Trou ...

  2. 常用zookeeper命令

    服务管理 启动ZK服务: zkServer.sh start 查看ZK状态: zkServer.sh status 停止ZK服务: zkServer.sh stop 重启ZK服务: zkServer. ...

  3. gensurf

    我来做个福利吧,首先将模糊文件.fis,加载到workspace中,这个大家都会,利用上面说的那个例子a = readfis('tipper');gensurf(a)这样默认的就是前两个输入的曲线,要 ...

  4. ES5与ES6对比

    ES5与ES6对比 1. 模块引用 1.在ES5里,引入React包基本通过require进行,代码类似这样: // ES5 var React = require('react'); var { C ...

  5. QT显示url图片

    QT 显示网络图片我目前的办法就是先下载下来 然后显示  如果有好的办法请相互交流一下 需要调用的头文件 #include <QNetworkAccessManager> #include ...

  6. Python不能用于大型项目?人们对Python的十大误解

    Python 类型系统的特点是拥有强大.灵活的类型操作. 维基百科上对此作出的阐述. 而存在一个不争而有趣的事实是, Python 是比Java更加强类型的. Java 对于原生类型和对象区分了类型系 ...

  7. 液晶屏MIPI接口与LVDS接口区别(总结)

    液晶屏接口类型有LVDS接口.MIPI DSIDSI接口(下文只讨论液晶屏LVDS接口,不讨论其它应用的LVDS接口,因此说到LVDS接口时无特殊说明都是指液晶屏LVDS接口),它们的主要信号成分都是 ...

  8. python_第一章

    从今天开始,正式开始学习python书籍:python 编程:从入门到实践. 感兴趣的读者可以去网上搜索这本书,适合读者入门,读下来,不会有任何 晦涩难懂的知识. 1.排序: 正排:sort()    ...

  9. c# create html table test

    string html = "<html><head><title>44444444</title>"; html += @&quo ...

  10. 分布式理论——quorum原理

    编者按:本篇文章是网上一些文章的合集,并不是原创,谢谢各位的分享. 一.基于Quorum投票的冗余控制算法 Quorom 机制,是一种分布式系统中常用的,用来保证数据冗余和最终一致性的投票算法,其主要 ...