CXF报错[1 counts of IllegalAnnotationExceptions]and[Two classes have the same XML type name]and[Use @XmlType.name and @XmlType.namespace to assign different names to them]

启动时CXF报错如下:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://service.facade.masopen.shengpay.com/}verifyResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
    this problem is related to the following location:
        at com.shengpay.masopen.facade.model.verify.VerifyResponse
        at private com.shengpay.masopen.facade.model.verify.VerifyResponse com.shengpay.masopen.facade.service.jaxws_asm.VerifyResponse._return
        at com.shengpay.masopen.facade.service.jaxws_asm.VerifyResponse
    this problem is related to the following location:
        at com.shengpay.masopen.facade.service.jaxws_asm.VerifyResponse

提示很明确:

Two classes have the same XML type name "{http://service.facade.masopen.shengpay.com/}verifyResponse"

存在两个类名=verifyResponse的xml type name

给出的处理方案是

Use @XmlType.name and @XmlType.namespace to assign different names to them.

使用@xmlType的name和namespace做区分

原来,WebService在发布的时候:对webservice里面得每个方法都生成一个类,生成的类名为: methodName + "Response",所以就回导致生成的类和原来的类有两个相同的xml type。

请看接口定义:

@WebService
public interface RealNameVerifyService {
    /**
     * 实名认证处理...
     * @param request
     * @return
     */
    
    VerifyResponse verify(VerifyRequest request) throws BusinessException;
}

方法名是verify,返回值是VerifyResponse,而webSwevice也会为我的方法生成一个类verifyResponse,这就冲突了。

解决方案常用有两个:

1.修改返回对象名称,不再使用VerifyResponse类名

2.使用@WebMethod指定生成的类名

@WebService
public interface RealNameVerifyService {
    /**
     * 实名认证处理...
     * @param request
     * @return
     */
    @WebMethod(operationName="wsVerify")
    VerifyResponse verify(VerifyRequest request) throws BusinessException;
}

 

参考:

http://stackoverflow.com/questions/4254334/illegalannotationexception-two-classes-have-the-same-xml-type-name

http://asialee.iteye.com/blog/1913480

原文地址:https://www.cnblogs.com/huahua035/p/5575208.html