我有一个第三方jar,其中包含带有@javax.xml.ws.WebServiceClient
注释的类SampleClass。我在我的REST层项目中使用了CXF而不是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)
答案 0 :(得分:0)
我们在我们的类中使用了Super(),它从Service扩展而来。 父“Service”类的代码是
反过来调用静态方法“Provider.provider()”来加载 运行时的提供者。 代码是
Javadoc对此方法的评论是:
块引用
创建一个新的提供者对象。
用于定位要使用的提供程序子类的算法包括 以下步骤:
块引用
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契约的约束。因此,类名/包可能会在将来的版本中发生变化。