Web Service : com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
Two classes have the same XML type name
系統環境:
JBoss: JBoss_4.2.2.GA
JDK: JDK1.6.0_14
IDE: NetBeans 6.9
code :
@WebService()
public class Trade {
@WebMethod(operationName = "gameOrder")
public GameOrderResponse gameOrder(
@WebParam(name = "GameOrderId") String gameOrderId,
@WebParam(name = "GameCode") String gameCode) {
GameOrderResponse response = null;
....
return response;
}
}
Error:
java.lang.IllegalStateException: Cannot build JAXB context
......
......
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://ws.billing.lkt.com/}gameOrderResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.lkt.billing.ws.type.GameOrderResponse
at private com.lkt.billing.ws.type.GameOrderResponse com.lkt.billing.ws.jaxws.GameOrderResponse._return
at com.lkt.billing.ws.jaxws.GameOrderResponse
this problem is related to the following location:
at com.lkt.billing.ws.jaxws.GameOrderResponse
Solution:
JAX-WS 會為 annotation @WebMethod 的每個方法, 自動生成一個 message element, 名為 methodName + "Response" ; 恰巧 return object 的 class 也命名相同, 因此會有衝突.
方法一 : 不要使用到 methodName + "Response" 來命名 response classes.
方法二 : 使用 @XMLType 指定不同的 namespaces 給 message elements.
Reference:
http://stackoverflow.com/questions/4254334/illegalannotationexception-two-classes-have-the-same-xml-type-name