3

我正在使用 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

任何帮助表示赞赏。提前致谢。

4

3 回答 3

0

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

<parameter name="ServiceObjectSupplier"
locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
于 2014-02-20T14:09:30.830 回答
0

您只需将以下代码放入您的 applicationContext.xml 文件中。

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

Spring 会自动将 applicationContext 分配给 ApplicationContextHolder。

于 2015-05-17T12:45:59.577 回答
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" />
于 2017-06-06T13:41:40.283 回答