ClassCastException:无法强制转换为com.sun.xml.internal.bind.v2.runtime.reflect.Accessor [英] ClassCastException: Cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor

查看:1528
本文介绍了ClassCastException:无法强制转换为com.sun.xml.internal.bind.v2.runtime.reflect.Accessor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SOAP Web服务,我试图在应用程序内部调用。我使用cxf-codegen-plugin(3.1.10)从WSDL生成源。

I have a SOAP webservice that I am trying to call inside of an application. I am using the cxf-codegen-plugin (3.1.10) to generate sources from the WSDL.

使用生成的客户端,如果我在应用程序中调用webservice,它很棒。但是,我还在应用程序中使用另一个JAXB实例来导致问题。

Using the generated client, if I call the webservice within the application, it works great. However, I am also using another JAXB instance against the same package within the application which is causing an issue.

例如,以下方法效果很好:

For example, the following works great:

OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);

但是,在此之前初始化新的JAXB实例会导致 getOutboundServicePort()调用失败:

However, initializing a new JAXB instance right before causes the getOutboundServicePort() call to fail:

JAXBContext.newInstance(SendMessageRequest.class);

OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);

使用以下堆栈跟踪:

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

到目前为止我尝试过的事情:

Things I have tried so far:

来自Webservice编组错误的JAXB类

  • I have no endorsed jars in my JDK folder, so this answer does not apply
  • The jaxb-impl jar (2.2.11) is coming from camel-jaxb in my app so it seems very contained and not like this answer suggests.
  • This answer seems to describe the problem well, but the solution they took seems unclear to me.

创建JAXBContext的问题将对象编组为XML


  • 这个问题似乎与我的相同,但他们最终的解决方案不能为我的情况工作(见下文)

Netbeans with JAXB Random ClassCastException ..无法转换为com.sun.xml.bind.v2.runtime.reflect。访问者


  • 我尝试了接受的解决方案 System.setPro perty(com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize,true); 哪个 工作。但是,在我的环境中,不幸的是,设置此属性不是我的选择。另外,看起来它有点像黑客并没有解决真正的问题(除非我误解了它)。

  • I tried the accepted solution System.setProperty( "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true"); which does work. However, setting this property is not an option for me unfortunately in my environment. Plus, it seems like it's a bit of a hack that does not address the real issue (unless I'm misunderstanding it).

我准备用我留下的小绳子挂上自己。我在这里缺少什么?

I'm about to hang myself with the little rope I have left. What am I missing here?

推荐答案

我不想回答我自己的问题,但我想确保解决方案我最终记录清楚。

I hate to answer my own question, but I wanted to make sure the solution I ended up going with was documented clearly.

根本问题是camel-jaxb引入的jaxb-impl jar与JDK 8提供的版本冲突。

The root issue was that the jaxb-impl jar brought in by camel-jaxb was conflicting with the JDK 8 provided version.

这个答案更清楚地描述了发生的事情:

This answer describes what is happening more clearly:


当我尝试将JAXB升级到比JDK附带的更新的
版本时,我遇到了同样的错误。 Java在运行时遇到两个或更多
的JAXB实例,无法确定
使用哪个版本。

I encountered the same error when I tried to upgrade JAXB to a newer version than what came with the JDK. Java encountered two or more instances of JAXB at runtime and could not decide which version to use.

就我而言,我只是排除了camel-jaxb附带的jaxb-impl,并且应用程序开始正常工作。

In my case, I simply excluded the jaxb-impl that came with camel-jaxb and the application started working correctly.

这篇关于ClassCastException:无法强制转换为com.sun.xml.internal.bind.v2.runtime.reflect.Accessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆