第一种:获取根目录下的文件名

ApplicationContext ac = new ClassPathXmlApplicationContext("../mvc-dispatcher-servlet.xml");

第二种

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

第三种

ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc);

第四种

extends ApplicationObjectSupport;

通过set方法注入,

第五种

implements ApplicationContextAware  实现的类必须注解@Component,否则还是为null

private static ApplicationContext apptext;

通过set方法注入

@Override
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
// TODO Auto-generated method stub
AsteriskeventListenerInit.apptext=arg0;
}

通过读取配置文件生成的applicationcontext,如果,配置文件内有如任务调度这样的配置,会造成多个任务触发,请小心。

spring 获取ApplicationContext的更多相关文章

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

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

  2. Spring获取ApplicationContext

    在Spring+Struts+Hibernate中,有时需要使用到Spring上下文.项目启动时,会自动根据applicationContext配置文件初始化上下文,可以使用ApplicationCo ...

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

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

  4. 手动获取spring的ApplicationContext和bean对象

    WEB项目: 方法1: 1 ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(S ...

  5. spring获取webapplicationcontext,applicationcontext几种方法详解

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

  6. Spring Boot 获取ApplicationContext

    package com.demo; import org.springframework.beans.BeansException; import org.springframework.contex ...

  7. 怎么获取Spring的ApplicationContext

    在 WEB 开发中,可能会非常少须要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获 ...

  8. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...

  9. spring 代码中获取ApplicationContext(@AutoWired,ApplicationListener)

    2017年度全网原创IT博主评选活动投票:http://www.itbang.me/goVote/234    学习spring框架时间不长,一点一滴都得亲力亲为.今天忽然觉得老是通过@Autowir ...

随机推荐

  1. vue学习1

    1.<div id="app">{{message}}<input v-model="message"></div>new ...

  2. mysql05---游标

    drop procedure p12$ //删除存储过程 //游标cursor,一条sql对应n条资源,取出资源的接口/句柄就是cursor, 一条sql产生的n条结果不是一次性全部输出,而是返回一个 ...

  3. Visual C++ 2010入门教程

    <Visual C++ 2010入门教程>系列一:关于Visual Studio.VC和C++的那些事   作者:董波 日期:2010.6.14 写在前面 在我还在上学的时候,我选择了C+ ...

  4. Persisting Data to the Device

    Persisting Data to the Device Edit PagePage History Overview The Android framework offers several op ...

  5. 在 Ubuntu 16.04 中安装支持 CPU 和 GPU 的 Google TensorFlow 神经网络软件

    TensorFlow 是用于机器学习任务的开源软件.它的创建者 Google 希望提供一个强大的工具以帮助开发者探索和建立基于机器学习的应用,所以他们在去年作为开源项目发布了它.TensorFlow ...

  6. CSYZDay2模拟题解

    T1.rotate [问题描述] ZYL有N张牌编号分别为1, 2,……,N.他把这N张牌打乱排成一排,然后他要做一次旋转使得旋转后固定点尽可能多.如果第i个位置的牌的编号为i,我们就称之为固定点.旋 ...

  7. bzoj 1127 KUP —— 最大子矩形+答案构造

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1127 首先,把权值 > 2*k 的点作为“坏点”,然后在图中用悬线法找权值最大的子矩形 ...

  8. vue 基础知识随笔

    在vue2.0中一个vue实例的生命周期中已经没有ready()了,在vue1.0中才有ready();在vue2.0中立即执行函数使用mounted v-for 参数顺序更新: 数组中使用(valu ...

  9. MD5加密 和Sha256加密

    //MD5加密 private static string GetMd5Hash(string emailAddress) { byte[] data = MD5.Create().ComputeHa ...

  10. C# 混淆 反编译

    .net破解一(反编译,反混淆-剥壳) http://www.cnblogs.com/jio92/p/de4dot.html C#学习系列-String与string的区别 http://www.cn ...