如何阻止cxf尝试接管javax.xml.ws.spi.Provider的默认实现?

时间:2014-03-26 14:55:57

标签: cxf karaf

Karaf 2.3.2

据我所知,我的代码或容器配置中没有引用Apache cxf,但是当我尝试使用Exchange Web服务时,cxf接管了jax实现,因为我没有已安装cxf:

./ data / karaf.out:javax.xml.ws.spi.FactoryFinder $ ConfigurationError:找不到提供者org.apache.cxf.jaxws.spi.ProviderImpl

我创建了文件META-INF \ services \ javax.xml.ws.spi.Provider,内容为com.sun.xml.internal.ws.spi.ProviderImpl,但是在Karaf中这似乎没有注册。

尽管没有引用cxf,但为什么它试图加载cxf的任何想法?或者是否有另一种方法来强制使用默认实现?

非常感谢

对于ref,似乎试图加载cxf实现的provider.provide()方法

/** 
 * 
 * Creates a new provider object. 
 * <p>
 * The algorithm used to locate the provider subclass to use consists 
 * of the following steps: 
 * <p>
 * <ul>
 * <li>
 *   If a resource with the name of 
 *   <code>META-INF/services/javax.xml.ws.spi.Provider</code>
 *   exists, then its first line, if present, is used as the UTF-8 encoded 
 *   name of the implementation class. 
 * </li>
 * <li>
 *   If the $java.home/lib/jaxws.properties file exists and it is readable by 
 *   the <code>java.util.Properties.load(InputStream)</code> method and it contains 
 *   an entry whose key is <code>javax.xml.ws.spi.Provider</code>, then the value of 
 *   that entry is used as the name of the implementation class. 
 * </li>
 * <li>
 *   If a system property with the name <code>javax.xml.ws.spi.Provider</code>
 *   is defined, then its value is used as the name of the implementation class. 
 * </li>
 * <li>
 *   Finally, a default implementation class name is used. 
 * </li>
 * </ul>
 * 
 */ 
public static Provider provider() { 
    try { 
        Object provider = getProviderUsingServiceLoader(); 
        if (provider == null) { 
            provider = FactoryFinder.find(JAXWSPROVIDER_PROPERTY, DEFAULT_JAXWSPROVIDER); 
        } 
        if (!(provider instanceof Provider)) { 
            Class pClass = Provider.class; 
            String classnameAsResource = pClass.getName().replace('.', '/') + ".class"; 
            ClassLoader loader = pClass.getClassLoader(); 
            if(loader == null) { 
                loader = ClassLoader.getSystemClassLoader(); 
            } 
            URL targetTypeURL  = loader.getResource(classnameAsResource); 
            throw new LinkageError("ClassCastException: attempting to cast" + 
                   provider.getClass().getClassLoader().getResource(classnameAsResource) + 
                   "to" + targetTypeURL.toString() ); 
        } 
        return (Provider) provider; 
    } catch (WebServiceException ex) { 
        throw ex; 
    } catch (Exception ex) { 
        throw new WebServiceException("Unable to createEndpointReference Provider", ex); 
    } 
} 

2 个答案:

答案 0 :(得分:0)

首先你不应该安装CXF软件包,其次,你需要公开&#34; com.sun.xml.internal.ws.spi&#34;打包到系统包。

答案 1 :(得分:0)

事实证明,Karaf包含了FactoryFinder.java的实现,它在lib / endorsed文件夹中查找cxf实现。 我刚刚删除了这个文件夹。