简体   繁体   English

IllegalAnnotationException:两个类具有相同的 XML 类型名称

[英]IllegalAnnotationException: Two classes have the same XML type name

I am developing web service under JBoss 5 and Java 1.6.我正在 JBoss 5 和 Java 1.6 下开发 Web 服务。 What could possibly cause this exception?什么可能导致此异常? Below is my simplified web service code.下面是我简化的 Web 服务代码。

@Stateless
@WebService()
public class AccountWS {

@WebMethod()
public CreateAccountResponse createAccount(@WebParam(name = "request") CreateAccountRequest request) {
    return null;
}

And below is the full stack trace.下面是完整的堆栈跟踪。

16:19:03,421 ERROR [AbstractKernelController] Error installing to Real: name=vfsfile:/C:/Apps/jbdevstudio/jboss-eap/jboss-as/server/default/deploy/sif_esb.esb/ state=PreReal mode=Manual requiredState=Real
org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/C:/Apps/jbdevstudio/jboss-eap/jboss-as/server/default/deploy/sif_esb.esb/
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1440)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1158)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1099)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1633)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:935)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:985)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:823)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:782)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:403)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1633)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:935)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:985)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:775)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.registerProfile(AbstractProfileService.java:308)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:256)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
at org.jboss.Main.boot(Main.java:221)
at org.jboss.Main$1.run(Main.java:556)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Cannot build JAXB context
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.createJAXBContext(JAXWSMetaDataBuilder.java:984)
at org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder.buildWebServiceMetaData(JAXWSWebServiceMetaDataBuilder.java:151)
at org.jboss.ws.metadata.builder.jaxws.JAXWSServerMetaDataBuilder.setupProviderOrWebService(JAXWSServerMetaDataBuilder.java:50)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilderEJB3.buildMetaData(JAXWSMetaDataBuilderEJB3.java:76)
at org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect.start(UnifiedMetaDataDeploymentAspect.java:69)
at org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl.deploy(DeploymentAspectManagerImpl.java:129)
at org.jboss.wsf.container.jboss50.deployer.ArchiveDeployerHook.deploy(ArchiveDeployerHook.java:76)
at org.jboss.wsf.container.jboss50.deployer.AbstractWebServiceDeployer.internalDeploy(AbstractWebServiceDeployer.java:60)
at org.jboss.wsf.container.jboss50.deployer.WebServiceDeployerEJB.internalDeploy(WebServiceDeployerEJB.java:113)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
... 29 more
Caused by: org.jboss.ws.WSException: Failed to create JAXBContext
at org.jboss.ws.core.jaxws.CustomizableJAXBContextFactory.createContext(CustomizableJAXBContextFactory.java:114)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.createJAXBContext(JAXWSMetaDataBuilder.java:980)
... 39 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://kona.webservice.sif.unidata.com/}createAccountResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
    at com.unidata.sif.kona.account.message.CreateAccountResponse
    at private com.unidata.sif.kona.account.message.CreateAccountResponse com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse._return
    at com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse
this problem is related to the following location:
    at com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse

at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:448)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:297)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at org.jboss.ws.core.jaxws.CustomizableJAXBContextFactory.createContext(CustomizableJAXBContextFactory.java:108)
... 40 more

I found the cause of my problem.我找到了问题的原因。

This problem occurs because JAX-WS generates a class for each method and the class name is constructed by concatenating methodName + "Response" .出现这个问题是因为 JAX-WS 为每个方法生成一个类,并且类名是通过连接methodName + "Response"构造的。 In my case, the newly generated class by JAX-WS will have the same name as my response object .就我而言, JAX-WS 新生成的类将与我的响应对象具有相同的名称

Example:例子:

@Stateless
@WebService()
public class AccountWS {

    @WebMethod()
    public CreateAccountResponse createAccount(@WebParam(name = "request") CreateAccountRequest request) {
        return null;
    }
}

JAX-WS will generate a new class CreateAccountResponse for Web Method createAccount which has the same name as the response object. JAX-WS 将为与响应对象同名的 Web 方法createAccount生成一个新类CreateAccountResponse

Solution:解决方案:

Make sure that the name of the response object and method doesn't match .确保响应对象和方法的名称不匹配 The same thing applies to the method parameter as well.同样的事情也适用于方法参数。

You have two XML schema elements with the same name ( createAccountResponse ) and the same namespace ( http://kona.webservice.sif.unidata.com/ ) corresponding to the Java types com.unidata.sif.kona.account.message.CreateAccountResponse and com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse .您有两个具有相同名称 ( createAccountResponse ) 和相同名称空间 ( http://kona.webservice.sif.unidata.com/ ) 的 XML 模式元素,对应于 Java 类型com.unidata.sif.kona.account.message.CreateAccountResponsecom.unidata.sif.webservice.kona.jaxws.CreateAccountResponse As the second one is "automagicaly" generated by the WebMethod annotation, it will be easier changing the XMLType anotation for the message element.由于第二个是由 WebMethod 注释“自动”生成的,因此更改消息元素的 XMLType 注释会更容易。

To solve it, you should change the name for one of them, or define two separated namespaces (one for the message elements, and another one for the WS request and response components).要解决这个问题,您应该更改其中之一的name ,或者定义两个独立的命名空间(一个用于消息元素,另一个用于 WS 请求和响应组件)。 I recommend the last approach (two separated namespaces).我推荐最后一种方法(两个独立的命名空间)。

IE: IE:

1. Changing the name of the message element com.unidata.sif.kona.account.message.CreateAccountResponse . 1.更改消息元素com.unidata.sif.kona.account.message.CreateAccountResponse的名称。

@XMLType(name="CreateAccountResponseMsg", namespace="http://kona.webservice.sif.unidata.com")

2. Changing the namespace at message elements (package com.unidata.sif.kona.account.message ) 2.更改消息元素的命名空间(包com.unidata.sif.kona.account.message

@XMLType(name="CreateAccountResponse", namespace="http://kona.webservice.sif.unidata.com/message")

I got the same error but I couldn't ajust the classes with @XmlType annotation (coming from library) So another solution is to provide a com.unidata.sif.kona.account.message/package-info.java with following code inside我遇到了同样的错误,但我无法使用 @XmlType 注释(来自库)调整类所以另一个解决方案是提供一个com.unidata.sif.kona.account.message/package-info.java里面有以下代码

@javax.xml.bind.annotation.XmlSchema(namespace = "http://kona.webservice.sif.unidata.com/")
package com.sopra.banking.processengine.servicecontract.v1_1.dto;

Another solution is to use @WebMethod(operationName="differentFromMethodName") .另一种解决方案是使用@WebMethod(operationName="differentFromMethodName") This will even change the interface method name on the client.这甚至会更改客户端上的接口方法名称。 JAX-WS still generates the classes for both wsgen and wsimport using the SEI's method name; JAX-WS 仍然使用 SEI 的方法名称为 wsgen 和 wsimport 生成类; but now the message element classes are different than the JAX_WS internally generated ones.但现在消息元素类与 JAX_WS 内部生成的不同。

I did not want to touch the wsgen generated classes (message element classes).我不想触及 wsgen 生成的类(消息元素类)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两个类具有相同的 XML 类型名称 - Two Classes have same XML type name 两个类具有相同的XML类型名称“objectFactory” - Two classes have the same XML type name “objectFactory” 使用两个类具有相同的 XML 类型名称 - Use two classes have the same XML type name 获取 JAXB 异常,例如“两个类具有相同的 XML 类型名称...” - Getting the JAXB exception like "Two classes have the same XML type name..." wsdl2java两个类具有相同的XML类型名称“{http://***.***。$。* * / * / / / / / *}} objectFactory” - wsdl2java Two classes have the same XML type name “{http://***.***.***.***/***/***/***}objectFactory” IllegalAnnotationExceptions:两个类具有相同的XML类型名称。 CXF插件生成的代码 - IllegalAnnotationExceptions: Two classes have the same XML type name. Code generated by CXF plugin java +消费SOAP Web服务+“两个类具有相同的XML类型名称……” - java + Consuming a SOAP web service + “Two classes Have the same XML type name …” jaxb2-maven-plugin 在生成 xsd 时忽略命名空间 - 两个类具有相同的 XML 类型 - jaxb2-maven-plugin ignores namespace when generating xsd - Two classes have the same XML type 如何创建两个具有相同名称,签名和返回类型的方法的类,就像它们实现相同的接口一样 - How to make two classes which both have method with the same name, signature and return type behave like they would implement the same interface 我的 Java 应用程序中的两个类具有相同的限定名称 - Two classes in my java app have the same Qualified name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM