org.apache.axis2.AxisFault:Axis2在.aar文件中找不到Spring的ApplicationContext

时间:2013-06-19 10:32:40

标签: spring axis2

我正在使用Axis2,Spring和Hibernate。我使用以下命令创建了.aar file

jar cvf someName.aar *  

我的.aar文件如下所示:

 _ classFilesWithInPackage (E.g. com/test/.../fileName.java)  
|_ META-INF/(MANIFEST.MF and services.xml)  
|_ applicationContext.xml  
|_ lib/required jars  

我的services.xml

<serviceGroup>
    <service name="SpringInitializationService" class="com.test.service.SpringInitService">
        <description>
            This web service initializes Spring.
        </description>
        <parameter name="ServiceClass">com.test.service.SpringInitService
        </parameter>
        <parameter name="ServiceTCCL">composite</parameter>
        <parameter name="load-on-startup">true</parameter>
    </service>
    <service name="TestService">
        <Description>
            Policy Web Service
        </Description>
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
        </messageReceivers>
        <parameter name="ServiceClass" locked="false">com.test.service.TestService
        </parameter>
        <parameter name="ServiceObjectSupplier">
            org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
        </parameter>
        <parameter name="SpringBeanName">axis2SpringIntegrationService</parameter>
        <parameter name="SpringContextLocation">applicationContext.xml</parameter>
    </service>
</serviceGroup>  

我已经实现了接口ServiceLifeCycle并覆盖了以下方法。参考网站http://fazlansabar.blogspot.com.es/2012/04/apache-axis2-tutorial-integrating-with.html

public class SpringInitService implements ServiceLifeCycle {

    ClassLoader classLoader = null;
    ClassPathXmlApplicationContext appCtx = null;

    @Override
    public void shutDown(ConfigurationContext configContext, AxisService axisService) {
        appCtx = null;
        classLoader = null;     
    }

    @Override
    public void startUp(ConfigurationContext configContext, AxisService axisService) {

        System.out.println("Inside Spring Init");

        try {
            classLoader = axisService.getClassLoader();
            appCtx = new ClassPathXmlApplicationContext(new String[] {"classpath:**applicationContext.xml"}, false);
            appCtx.setClassLoader(classLoader);
            appCtx.refresh();
        } catch (Exception e) {
            e.printStackTrace();
        }       

        System.out.println("Out of Spring Init");
    }

}  

当我创建.aar文件并在WSO2 server中部署时,它已成功部署,com.test.service.SpringInitService类也在启动时初始化,没有错误,因为我已经实现了ServiceLifeCycle接口。但是当我调用TestService中可用的任何服务(services.xml中的第二个服务)时,我最终出错了。

org.apache.axis2.AxisFault: Axis2 Can't find Spring's ApplicationContext  

有人请告诉我我做错了什么 同时澄清,

Whether my .aar folder structure is right?
Can we have more than one service in services.xml as above?
What is the best way to have Axis2, Spring and Hibernate together?  

更新
   我尝试按照Axis2网站的以下参考资料,但没有运气让它运转起来 http://axis.apache.org/axis2/java/core/docs/spring.html

任何帮助都是赞赏的。 在此先感谢。

3 个答案:

答案 0 :(得分:0)

尝试在services.xml中的spring初始化服务中添加它:

<parameter name="ServiceObjectSupplier"
locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>

答案 1 :(得分:0)

您只需将以下代码放在applicationContext.xml文件中即可。

 <bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />

Spring会自动将applicationContext分配给ApplicationContextHolder。

答案 2 :(得分:0)

实施您自己的 ApplicationContextHolder

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextHolder implements ApplicationContextAware {

    private static ApplicationContext appCtx;

    public ApplicationContextHolder() {}

    /** Spring supplied interface method for injecting app context. */
    public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {
        appCtx = applicationContext;
    }

    /** Access to spring wired beans. */
    public static ApplicationContext getContext() {
        return appCtx;
    }

}

settings.xml

中使用它
<bean id="applicationContext"
class="org.ravinda.service.spring.ApplicationContextHolder" />