问题描述
首先看我的代码:UserSerivceImpl.java@WebServicepublic class UserSerivceImpl implements UserService {private UserDao userDao;public void setUserDao(UserDao userDao){this.userDao = userDao;}public List<User> getAllUsers() {// TODO Auto-generated method stubreturn userDao.getAllUserList();}}UserDao.java public List<User> getAllUserList() { List rows = jt.queryForList("select id as userid,username,email as useremail,profile as userage from tbl_user");List<User> list = new ArrayList<User>(); if(rows == null){//rows = new ArrayList<User>();User user = new User();user.setUserage("21");user.setUseremail("jack@123.com");user.setUserid("23");user.setUsername("jack");list.add(user);}else{//rows !=nullfor(int i=0;i<rows.size();i++){User user1 = new User();Hashtable ht = (Hashtable)rows.get(i);user1.setUserage(ht.get("userage")!=null?(String)ht.get("userage"):"2");user1.setUseremail(ht.get("useremail")!=null?(String)ht.get("useremail"):"2");user1.setUserid(ht.get("userid")!=null?(String)ht.get("userid"):"2");user1.setUsername(ht.get("username")!=null?(String)ht.get("username"):"2");list.add(user1);System.out.println("username == "+user1.getUsername());}} return list;}客户端代码:JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();factory.getInInterceptors().add(new LoggingInInterceptor());factory.getOutInterceptors().add(new LoggingOutInterceptor());factory.setAddress("http://localhost:8080/CxfSpring/service/UserManager");factory.setServiceClass(UserService.class);UserService service = (UserService)factory.create();//User user = service.getUserByID("1");//System.out.println("username == "+user.getUsername());List<User> list = service.getAllUsers();System.out.println("list size == "+list);运行客户端 ,然后提示的错误是:Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtableat org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)at $Proxy38.getAllUsers(Unknown Source)at test.SoapExample.main(SoapExample.java:53)Caused by: org.apache.cxf.binding.soap.SoapFault: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtableat org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:99)at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:733)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2201)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2071)at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1925)at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188)at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:662)at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)... 2 more请问这是什么错误?怎么解决? 问题补充:谢谢你。就是这个地方有问题。同时user1.setUserid(ht.get("userid")!=null?(Integer)ht.get("userid")+"":"2");这一句也是要修改的。lizhi92574 写道
解决方案
Hashtable ht = (Hashtable)rows.get(i); Map ht = (Map)rows.get(i);
解决方案二:
Hashtable ht = (Hashtable)rows.get(i);确定这样可以转么?
解决方案三:
引用Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtable 类型转换错误,引入 Hashtable 错误了,引入一个LinkedCaseInsensitiveMap 对象。