java类:
public class MySpringContext implements ApplicationContextAware{
private static ApplicationContext context;//声明一个静态变量保存
@SuppressWarnings("static-access")
public void setApplicationContext(ApplicationContext contex) throws BeansException {
this.context=contex;
}
public static ApplicationContext getContext(){
return context;
} }
 
spring配置文件中配置:
<bean class="com.tsingsoft.basedata.sendMessage.MySpringContext"></bean>

调用类调用:

ApplicationContext app =MySpringContext.getContext();

程序中非action获得spring容器的更多相关文章

  1. Spring 读书笔记-----使用Spring容器(一)

    pring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spri ...

  2. (转)Spring 读书笔记-----使用Spring容器(一)

    Spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spr ...

  3. Spring注解@Resource和@Autowired区别对比、spring扫描的默认bean的Id、程序获取spring容器对象

    -------------------------注解扫面的bean的ID问题-------------------------- 0.前提需要明白注解扫描出来的bean的id默认是类名首字母小写,当 ...

  4. 资深程序员总结:彻底理解Spring容器和应用上下文

    点关注,不迷路:持续更新Java架构相关技术及资讯热文!!! 有了Spring之后,通过依赖注入的方式,我们的业务代码不用自己管理关联对象的生命周期.业务代码只需要按照业务本身的流程,走啊走啊,走到哪 ...

  5. 获取Spring容器中的Bean

    摘要 SpringMVC框架开发中可能会在Filter或Servlet中用到spring容器中注册的java bean 对象,获得容器中的java bean对象有如下方法 Spring中的Applic ...

  6. Spring容器-ApplicationContext的单例设计

    Spring容器-ApplicationContext的单例设计   每次通过new创建一个ApplicationContext容器,都会执行refresh方法,看源代码了解到这个refresh方法会 ...

  7. 监听器如何获取Spring配置文件(加载生成Spring容器)

    Spring容器是生成Bean的工厂,我们在做项目的时候,会用到监听器去获取spring的配置文件,然后从中拿出我们需要的bean出来,比如做网站首页,假设商品的后台业务逻辑都做好了,我们需要创建一个 ...

  8. BeanFactory到WebApplicationContext的结构 以及bean和spring容器的关系

    BeanFactory: Ioc 容器 ApplicationContext: Spring容器 WebApplicationContext需要ServletContext实例,也就是说它必须在拥有W ...

  9. Spring容器深入(li)

    spring中最常用的控制反转和面向切面编程. 一.IOC IoC(Inversion of Control,控制倒转).对于spring框架来说,就是由spring来负责控制对象的生命周期和对象间的 ...

随机推荐

  1. week4_motion_of_ball_1(小球运动)——最基本

    # Ball motion with an explicit timer import simplegui # Initialize globals width = 600 height = 600 ...

  2. Opencv2系列学习笔记2(图像的其它操作)

    本节主要涉及到图像的领域.算术操作以及如何操作图像感兴趣的区域. 一:邻域操作 以下例子主要对图像进行锐化.基于拉普拉斯算子<后面讨论>.这幅图像的边缘部分将得到放大,细节部分将更加的锐利 ...

  3. iOS 8 强制横屏

    最近用到视频播放功能:(Vitamio, 注:在Build Setting 里面的 Other Link Flag 添加-all_load) iOS 8的屏幕旋转比较坑, 使用以下代码可以强制旋转 - ...

  4. Python3.5.1 下使用HTMLParser报错

    pip 安装HTMLParser之后,import HTMLParser 使用的时候,报错"ImportError:Can't not find module markupbase" ...

  5. Google Code Jam Round 1C 2015 Problem A. Brattleship

    Problem You're about to play a simplified "battleship" game with your little brother. The ...

  6. (Problem 4)Largest palindrome product

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2 ...

  7. Spring IOC三种注入方式(接口注入、setter注入、构造器注入)(摘抄)

    IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转, Spring 框架的核心基于控制反转原理. 什么是控制反转?控制反转是一种将组件依赖关系的创建和管理置于程序外部的技 ...

  8. x64栈结构

    A function's prolog is responsible for allocating stack space for local variables, saved registers, ...

  9. 区间重合判断(pojg校门外的树)

    pojg:http://poj.grids.cn/practice/2808 解法1:以空间换时间: #include<stdio.h> #include<string.h> ...

  10. VC++在对话框中加入属性页

    当一个基于对话框的程序中有相当多的控件时,你一定会想到使用属性页来将这些控件分类放置.本文针对这种方法来讨论几种可能实现的方案. 方案一本方案的例子请见源代码打包文件中的Property1部分 在对话 ...