【发布时间】:2013-01-26 15:07:42
【问题描述】:
我在 Tomcat 上部署了一个 .aar 文件,Ubuntu 的 Axis2 平台。 我正在使用 Oracle JDK1.7 Tomcat 7.0.35 和 Axis2 1.6.2
最近我做了一个重构,使用 java.util.ServiceLoader 类来加载 一些类是动态的。
这是我的 aar 文件结构:
META-INF folder
services.xml Contains info about the web service
services folder
com.companyname...interfacename1 (contains implementation class name)
com.companyname...interfacename2 (contains implementation class name)
com.companyname...interfacename3 (contains implementation class name)
com folder
companyname folder
bla bla.class compiled class files here
在我的 Eclipse 开发环境中,我的方法运行时没有任何问题,但是当它们运行时 在 Axis2 Tomcat 平台中,ServiceLoader 类无法加载实现类。 可能是什么问题? 任何帮助表示赞赏。 谢谢。
【问题讨论】:
-
在 Apache Axis2 常见问题页面 link,有一个使用 Axis API 访问服务类加载器的建议,如下所示:AxisService myService = messageContext.getAxisConfiguration().getAxisService("serviceName"); AxisService myService = msgCtx.getAxisService();类加载器 clsLoader = myService.getServiceClassLoader();然后我可以这样调用: ServiceLoader.load(service,clsLoader) 感谢 Deepal Jayasinghe 的推荐!但是,此代码为我的代码带来了 Axis2 包依赖项。有没有改进的方法来做到这一点?
标签: java tomcat axis2 serviceloader