在接口中返回的list中如未指定泛型类型,报nor any of its super class is known to this context错误。
具体核心代码如下:
接口类
@WebService
@SOAPBinding(parameterStyle = ParameterStyle.WRAPPED, style = SOAPBinding.Style.DOCUMENT)
public interface IDCFacade {
@WebMethod(operationName = "FindDictClassById")
public String sayHellow(@WebParam(name = "word")
String word);
@WebMethod(operationName = "GetDefineList")
public List<?> getDefineList(@WebParam(name = "rootName")
String rootName);
}
实现类
@WebService(name = "CxfWebService", serviceName = "WebService", targetNamespace = "http://liuyun.cxf.webservice", endpointInterface = "liuyun.interfaces.IDCFacade")
@SOAPBinding(style = Style.DOCUMENT)
@SuppressWarnings("deprecation")
public class CxfWebService implements IDCFacade {
private ApplicationContext ctx = new ClassPathXmlApplicationContext(
"classpath:spring-config.xml");
public String sayHellow(String word) {
return "say helle " + word;
}
public List<?> getDefineList(String rootName) {
return DefineClass.getFromApplicationContext(ctx).getDefineList(rootName);
}
}
DefineClass类
public class DefineClass {
private static final Log log = LogFactory.getLog(DefineClass.class);
protected void initDao() {
// do nothing
}
public List<Sex> getDefineList(String rootClass) {
log.info("start getDefineList" + "----" + rootClass);
List<Sex> list = new ArrayList<Sex>();
if ("a".equals(rootClass) ) {
liuyun.pojo.Sex sex=new Sex();
sex.setId(1);
sex.setCode("001");
sex.setName("sex1");
list.add(sex);
sex=new Sex();
sex.setId(2);
sex.setCode("002");
sex.setName("sex2");
list.add(sex);
sex=new Sex();
sex.setId(3);
sex.setCode("003");
sex.setName("sex3");
list.add(sex);
}
log.info("return getDefineList");
return list;
}
public static DefineClass getFromApplicationContext(ApplicationContext ctx) {
return (DefineClass) ctx.getBean("DefineClass");
}
}
异常:
信息: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: class liuyun.pojo.Sex nor any of its super class is known to this context.
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:105)
at org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:89)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:368)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:183)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:163)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
这是java吧?
传递得用 json吧。。没有直接用list传递的吧 。。
基类加@XmlSeeAlso(Sex.class)就可以了