在CXF中,如果Web Service返回类型是Map的时候,比如方法签名如下
?
- @WebMethod??
- @WebResult?Map<String,?User>?getUserMap();??
此时如果运行程序会得到类似下面的异常
- ...??
- Caused?by:?com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:?2?counts?of?IllegalAnnotationExceptions??
- java.util.Map?is?an?interface,?and?JAXB?can't?handle?interfaces.??
- ????this?problem?is?related?to?the?following?location:??
- ????????at?java.util.Map??
- ????????at?private?java.util.Map?com.googlecode.garbagecan.cxfstudy.type.sample2.jaxws_asm.GetUserMapResponse._return??
- ????????at?com.googlecode.garbagecan.cxfstudy.type.sample2.jaxws_asm.GetUserMapResponse??
- java.util.Map?does?not?have?a?no-arg?default?constructor.??
- ????this?problem?is?related?to?the?following?location:??
- ????????at?java.util.Map??
- ????????at?private?java.util.Map?com.googlecode.garbagecan.cxfstudy.type.sample2.jaxws_asm.GetUserMapResponse._return??
- ????????at?com.googlecode.garbagecan.cxfstudy.type.sample2.jaxws_asm.GetUserMapResponse??
- ????at?com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)??
- ????at?com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)??
- ????at?com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)??
- ????at?com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1136)??
- ????at?com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)??
- ????at?com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)??
- ????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.newInstance(Unknown?Source)??
- ????at?javax.xml.bind.ContextFinder.find(Unknown?Source)??
- ????at?javax.xml.bind.JAXBContext.newInstance(Unknown?Source)??
- ????at?org.apache.cxf.jaxb.JAXBDataBinding.createContext(JAXBDataBinding.java:560)??
- ????at?org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:500)??
- ????at?org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:320)??
- ????...?25?more??
- ...??
如果把方法签名改为如下时
?
?