1

我有一个第三方 jar,其中包含带有@javax.xml.ws.WebServiceClient注释的类 SampleClass。我在我的项目中将 CXF 用于 REST 层而不是用于 Web 服务。但是,由于为我的项目配置了 CXF 基础架构,因此在我实例化它时它会尝试自动连接到 SampleClass(事实上,它在尝试这样做时会出错)。我想将该类用作简单的 POJO 而不是 Web 服务客户端。有没有办法告诉 CXF 忽略@javax.xml.ws.WebServiceClient注释?

仅供参考,我得到的例外是:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.cxf.common.injection.ResourceInjector.invokePostConstruct(ResourceInjector.java:302)
    at org.apache.cxf.common.injection.ResourceInjector.construct(ResourceInjector.java:86)
    at org.apache.cxf.bus.spring.Jsr250BeanPostProcessor.postProcessAfterInitialization(Jsr250BeanPostProcessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:357)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1308)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:430)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.apache.cxf.bus.spring.BusApplicationContext.<init>(BusApplicationContext.java:88)
    at org.apache.cxf.bus.spring.SpringBusFactory.createApplicationContext(SpringBusFactory.java:103)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:94)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:87)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:65)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:54)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:70)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:107)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:98)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:64)
    at javax.xml.ws.Service.<init>(Unknown Source)

Caused by: java.lang.NullPointerException
    at org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister.createCompatExtensor(WSDLExtensionRegister.java:63)
    at org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister.registerYokoCompatibleExtensors(WSDLExtensionRegister.java:47)
    ... 34 more
java.lang.ExceptionInInitializerError

Caused by: java.lang.NullPointerException
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:81)
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:141)
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:133)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:65)
    at javax.xml.ws.Service.<init>(Unknown Source)
4

1 回答 1

0

我们在从 Service 扩展的类中使用了 Super()。父“服务”类的代码是

http://grepcode.com/file/repo1.maven.org/maven2/javax.xml.ws/jaxws-api/2.2.8/javax/xml/ws/Service.java#92

进而调用静态方法“Provider.provider()”在运行时加载提供程序。代码是

http://grepcode.com/file/repo1.maven.org/maven2/javax.xml.ws/jaxws-api/2.2.8/javax/xml/ws/spi/Provider.java#Provider.provider%28% 29

对此方法的 Javadoc 注释是:

块引用

创建一个新的提供者对象。

用于定位要使用的提供程序子类的算法包括以下步骤:

  • 如果名称为 META-INF/services/javax.xml.ws.spi.Provider 的资源存在,则其第一行(如果存在)用作实现类的 UTF-8 编码名称。
  • 如果 $java.home/lib/jaxws.properties 文件存在并且它可以被 java.util.Properties.load(InputStream) 方法读取,并且它包含一个键为 javax.xml.ws.spi.Provider 的条目,那么该条目的值用作实现类的名称。
  • 如果定义了名为 javax.xml.ws.spi.Provider 的系统属性,则其值用作实现类的名称。
  • 最后,使用默认的实现类名。

块引用

CXF 似乎选择了第一种方式来加载它的 Provider 实现。即:“如果名称为 META-INF/services/javax.xml.ws.spi.Provider 的资源存在,则其第一行(如果存在)用作实现类的 UTF-8 编码名称。”

CXF jar 在 jar 中有这个文件,其中 Provider 类被称为 CXF 实现。由于这是用于查找的第一件事,因此将加载 CXF 的提供程序而不是默认提供程序。但是,我们的实现期望加载默认提供程序。

我们能想到的唯一可行的解​​决方法是自己在 META-INF\services 下添加文件 javax.xml.ws.spi.Provider 并将提供程序指定为默认实现类 com.sun.xml.internal.ws.spi .ProviderImpl。唯一的风险是 com.sun.xml.internal.ws.spi.ProviderImpl 类是 JRE 的内部实现,不受 API 合同约束。所以类名/包可能会随着未来的版本而改变。

于 2012-12-06T06:51:02.293 回答