为什么不能在 java 6 中将 GenericArrayTypeImpl 强制转换为 java.lang.Class,而在 java 7 中可以?
Why can't GenericArrayTypeImpl be cast to java.lang.Class in java 6, when it can in java 7?
我的实际问题是标题的推导,但标题是我问题的根本原因:
我正在开发 java Web 应用程序。我的应用程序要部署的服务器只接受 java 6 或更低版本 (WebLogic 10.3.2)
我需要在我的应用程序中调用网络服务。我在这方面的经验有限。我已经能够让它工作,但是当我将我的代码集成到 Web 应用程序中、编译和测试它时,我得到了这个错误:
Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to java.lang.Class
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ElementInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeElementInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RegistryInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.addRegistry(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(Unknown Source)
at com.sun.xml.internal.ws.developer.JAXBContextFactory.createJAXBContext(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.run(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at com.example.mypackage.MyClient.invokeService(MyClient.java:64)
at Test.main(Test.java:7)
我已将此错误追溯到 java 版本问题。它在 7 中工作,但如果我在 6 中编译,则在方法执行时抛出异常,这是我必须为 Web 应用程序做的。抛出我的异常的行是下面带有 NotificationRecieverSoapInterface.class
的行:
NotifikationRecieverSoap service = null;
try {
service = new NotifikationRecieverSoap(new URL("[myURL].svc?wsdl"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
NotificationRecieverSoapInterface notificationService = service.getPort(NotificationRecieverSoapInterface.class);
notifikationService.createNotificationRequest(logHeader, loginModule, parmV, priority, recipients);
Service.getPort()
-方法在两个 java 版本中似乎相同,所以我在那里不知所措。 sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
在 6 和 7 中也相同。
我在网上发现的最接近类似问题的是:http://forum.spring.io/forum/spring-projects/container/26020-classcastexception-genericarraytypeimpl-cannot-be-cast-to-class。不幸的是,这里的解决方案是 Spring 中存在错误,我没有使用它...
有没有人更具体地知道我的问题是什么,如果可以解决,仅使用 Java 6?
我还有很多代码要展示。我选择了我认为与问题最相关的部分。我可以根据要求提供 jax-ws-generated 类 数据结构,或样本 xml。
好的...我用这个方法生成了网络服务类:http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
我发现调用wsimport.exe时我使用了1.7JDK。这与我的 1.6 项目不兼容。使用在正确的 JDK 1.6 中找到的 wsimport.exe 重新生成 类 后,java 类 略有不同,并且与我的项目设置兼容。
我的实际问题是标题的推导,但标题是我问题的根本原因:
我正在开发 java Web 应用程序。我的应用程序要部署的服务器只接受 java 6 或更低版本 (WebLogic 10.3.2)
我需要在我的应用程序中调用网络服务。我在这方面的经验有限。我已经能够让它工作,但是当我将我的代码集成到 Web 应用程序中、编译和测试它时,我得到了这个错误:
Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to java.lang.Class
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ElementInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeElementInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RegistryInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.addRegistry(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(Unknown Source)
at com.sun.xml.internal.ws.developer.JAXBContextFactory.createJAXBContext(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.run(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at com.example.mypackage.MyClient.invokeService(MyClient.java:64)
at Test.main(Test.java:7)
我已将此错误追溯到 java 版本问题。它在 7 中工作,但如果我在 6 中编译,则在方法执行时抛出异常,这是我必须为 Web 应用程序做的。抛出我的异常的行是下面带有 NotificationRecieverSoapInterface.class
的行:
NotifikationRecieverSoap service = null;
try {
service = new NotifikationRecieverSoap(new URL("[myURL].svc?wsdl"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
NotificationRecieverSoapInterface notificationService = service.getPort(NotificationRecieverSoapInterface.class);
notifikationService.createNotificationRequest(logHeader, loginModule, parmV, priority, recipients);
Service.getPort()
-方法在两个 java 版本中似乎相同,所以我在那里不知所措。 sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
在 6 和 7 中也相同。
我在网上发现的最接近类似问题的是:http://forum.spring.io/forum/spring-projects/container/26020-classcastexception-genericarraytypeimpl-cannot-be-cast-to-class。不幸的是,这里的解决方案是 Spring 中存在错误,我没有使用它...
有没有人更具体地知道我的问题是什么,如果可以解决,仅使用 Java 6?
我还有很多代码要展示。我选择了我认为与问题最相关的部分。我可以根据要求提供 jax-ws-generated 类 数据结构,或样本 xml。
好的...我用这个方法生成了网络服务类:http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
我发现调用wsimport.exe时我使用了1.7JDK。这与我的 1.6 项目不兼容。使用在正确的 JDK 1.6 中找到的 wsimport.exe 重新生成 类 后,java 类 略有不同,并且与我的项目设置兼容。