简体   繁体   English

部署在Tomcat Web服务器上的Axis2 Web服务代码中的ServiceLoader用法

[英]ServiceLoader usage in Axis2 web service code deployed on Tomcat web server

I have an .aar file deployed on Tomcat,Axis2 platform in Ubuntu. 我在Ubuntu的Tomcat,Axis2平台上部署了一个.aar文件。 I'm using Oracle JDK1.7 Tomcat 7.0.35 and Axis2 1.6.2 我正在使用Oracle JDK1.7 Tomcat 7.0.35和Axis2 1.6.2

Recently I made a refactoring to use java.util.ServiceLoader class to load implementations of some classes dynamically. 最近,我进行了重构,以使用java.util.ServiceLoader类来动态加载某些类的实现。

Here is my aar file structure: 这是我的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

In my Eclipse Development environment, my methods run w/o any problem but when they run in Axis2 Tomcat platform, ServiceLoader class can not load implementation classes. 在我的Eclipse开发环境中,我的方法没有任何问题,但是当它们在Axis2 Tomcat平台中运行时,ServiceLoader类无法加载实现类。 What can be the problem? 可能是什么问题? Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

Just use one of your classes to obtain their classLoader,Then use it: 只需使用您的一个类来获取其classLoader,然后使用它:

    ClassLoader classLoader = com.companyname.blabla.MyClass1.getClassLoader();

    java.util.ServiceLoader.load(blabla.class,classLoader);

It works both in Tomcat,Axis2 deployed code and in development environment unit test code! 它可以在Tomcat,Axis2部署代码和开发环境单元测试代码中使用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM