CXF 發佈WS 1 counts of IllegalAnnotationExceptions 問題

今天第一次用CXF開發WebService ,在開發的過程中遇到一個問題錯誤如下:

Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://wsservice.service.ts.com/}testResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
	this problem is related to the following location:
		at com.ts.service.wsservice.vo.TestResponse
		at private com.ts.service.wsservice.vo.TestResponse com.ts.service.wsservice.jaxws_asm.TestResponse._return
		at com.ts.service.wsservice.jaxws_asm.TestResponse
	this problem is related to the following location:
		at com.ts.service.wsservice.jaxws_asm.TestResponse

	at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(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.v2.ContextFactory.createContext(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
	at javax.xml.bind.ContextFinder.find(Unknown Source)
	at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
	at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:279)
	at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:172)
	at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:427)
	at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:295)
	... 56 more


很是鬱悶,當我看到錯誤中有 testReponse的的時候,突然意識到自己發佈方法類型不就是 這個嗎?而接口的名稱是test,CXF在發佈的這個方法響應的xml就是

test + Response,這個正好和接口的方法名稱衝突嗎?

package com.ts.service.wsservice;

import javax.jws.WebService;

import com.ts.service.wsservice.vo.TestRequest;
import com.ts.service.wsservice.vo.TestResponse;

@WebService
public interface ITestService {
	public TestResponse test(TestRequest req) ;
}

於是把方法改成

package com.ts.service.wsservice;

import javax.jws.WebService;

import com.ts.service.wsservice.vo.TestRequest;
import com.ts.service.wsservice.vo.TestResponse;

@WebService
public interface ITestService {
	public TestResponse testWS (TestRequest req) ;
}

重新啓動了一下Tomcat,O了。

本人遇到報的錯誤的問題只是本人寫代碼中的Bug,並不代表你寫代碼中遇到此Bug,用此方法就可以,希望不要拍磚

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章