读书人

程序中非action取得spring容器

发布时间: 2013-09-05 16:02:07 作者: rapoo

程序中非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();

读书人网 >编程

热点推荐