首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

程序中非action取得spring容器

2013-09-05 
程序中非action获得spring容器java类:public class MySpringContext implements ApplicationContextAware{

程序中非action获得spring容器

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

热点排行