我有一个SOAP Web服务,我试图在应用程序内部调用.我使用cxf-codegen-plugin(3.1.10)从WSDL生成源代码.
使用生成的客户端,如果我在应用程序中调用Web服务,它可以很好地工作.但是,我还在应用程序中使用另一个JAXB实例来导致问题.
例如,以下工作很好:
OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);
Run Code Online (Sandbox Code Playgroud)
但是,在之前初始化新的JAXB实例会导致getOutboundServicePort()
调用失败:
JAXBContext.newInstance(SendMessageRequest.class);
OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);
Run Code Online (Sandbox Code Playgroud)
使用以下堆栈跟踪:
Caused by: java.lang.ClassCastException: outbound.model.standard.StandardOutboundMessage$JaxbAccessorF_messageUUId cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.instanciate(OptimizedAccessorFactory.java:190)
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:179)
at com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:271)
at com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:77)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:113)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:166)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:153)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:305)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:152)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96)
at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98)
at com.sun.xml.internal.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:79)
... 25 more
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的事情:
具有JAXB Random ClassCastException的Netbeans ..无法强制转换为com.sun.xml.bind.v2.runtime.reflect.Accessor
System.setProperty( "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true");
,其做的工作.但是,在我的环境中,不幸的是,设置此属性不是我的选择.此外,它似乎是一个没有解决真正问题的黑客攻击(除非我误解它).我准备用我留下的小绳子挂上自己.我在这里错过了什么?
我在尝试通过 Maven 运行我的 JUnit 测试时遇到了这个错误,即使它们在 Eclipse 中本地通过。我的解决方案是@BeforeClass
放入:
System.setProperty("javax.xml.bind.JAXBContext", "com.sun.xml.internal.bind.v2.ContextFactory");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11609 次 |
最近记录: |