首先看我的代码:
UserSerivceImpl.java
[code="java"]
@WebService
public class UserSerivceImpl implements UserService {
private UserDao userDao;
public void setUserDao(UserDao userDao){
this.userDao = userDao;
}
public List<User> getAllUsers() {
// TODO Auto-generated method stub
return userDao.getAllUserList();
}
}
[/code]
UserDao.java
[code="java"]
public List 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 !=null
for(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;
}
[/code]
客户端代码:
[code="java"]
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);
[/code]
运行客户端 ,然后提示的错误是:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to java.util.Hashtable
at 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.Hashtable
at 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
请问这是什么错误?怎么解决?