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

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

问题描述

我有一个 SOAP 网络服务,我试图在应用程序内部调用它.我正在使用 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.

使用生成的客户端,如果我在应用程序中调用 web 服务,效果很好.但是,我还针对应用程序中的同一个包使用了另一个 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.

例如,以下效果很好:

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:

来自 Web 服务编组错误的 JAXB 类

  • 我的 JDK 文件夹中没有认可的 jar,因此此答案不适用
  • jaxb-impl jar (2.2.11) 来自我的应用中的camel-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 的问题

  • 这个问题似乎与我的相同,但他们最终采用的解决方案不适用于我的情况(见下文)

使用 JAXB 的 Netbeans随机 ClassCastException ..无法转换为 com.sun.xml.bind.v2.runtime.reflect.Accessor

  • 我尝试了接受的解决方案 System.setProperty( "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true"); does 工作.但是,不幸的是,在我的环境中,设置此属性不是我的选择.另外,这似乎是一个没有解决真正问题的黑客(除非我误解了它).
  • 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天全站免登陆