Chinaunix首页 | 论坛 | 博客
  • 博客访问: 518482
  • 博文数量: 135
  • 博客积分: 3568
  • 博客等级: 中校
  • 技术积分: 1942
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-19 17:52
文章分类

全部博文(135)

文章存档

2012年(29)

2011年(41)

2010年(26)

2009年(12)

2008年(9)

2007年(12)

2006年(6)

分类: Java

2012-02-22 11:21:04

仅仅是做个备注,好记性不如烂笔头啊。是参考了 Axis2与Spring 结合时 的使用方法。

me/test/ApplicationContextHolder.java
  1. package me.test;

  2. import org.springframework.beans.Bean***ception;
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.ApplicationContextAware;

  5. /**
  6.  * 如果要在Spring管理的 Bean 中访问 ApplicationContext,请让该 Bean 实现 ApplicationContextAware 接口。
  7.  * 如果要在 Servlet,Listener中访问 ApplicationContext,请使用WebApplicationContextUtils。
  8.  * 如果要在非 Spring管理的对象中或静态方法内(需慎重考虑),请参考本例。
  9.  *
  10.  * 注意:使用时要注意初始化的先后顺序,防止空指针异常。
  11.  *
  12.  * 参考:org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder
  13.  * org.springframework.context.access.ContextSingletonBeanFactoryLocator
  14.  */
  15. public class ApplicationContextHolder implements ApplicationContextAware {

  16.     private static ApplicationContext appCtx;

  17.     public void setApplicationContext(ApplicationContext applicationContext)
  18.             throws Bean***ception {
  19.         appCtx = applicationContext;
  20.     }

  21.     public static ApplicationContext getContext() {
  22.         return appCtx;
  23.     }
  24. }
applicationContext.xml
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <beans xmlns=""
  3.        xmlns:xsi=""
  4.        xmlns:util=""
  5.        xmlns:aop=""
  6.        xmlns:tx=""
  7.        xsi:schemaLocation="
  8. /spring-beans-2.5.xsd
  9. /spring-util-2.5.xsd
  10. /spring-aop-2.5.xsd
  11. /spring-tx-2.5.xsd">

  12.   <bean class="me.test.ApplicationContextHolder" />

  13. </beans>

阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~