我正在使用 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
任何帮助表示赞赏。提前致谢。