用Restlet测试获取用户信息模块时,报ServerResponse不能转换为User
来源:6-9 用户模块所有功能自测试
lin_xin
2018-03-22
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)</pre><p><b>Root Cause</b></p><pre>java.lang.ClassCastException: com.mmall.common.ServerResponse cannot be cast to com.mmall.pojo.User com.mmall.controller.UserController.getUserInfo(UserController.java:58) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" ><h3>Apache Tomcat/9.0.2</h3></body></html>
3回答
-
: com.mmall.common.ServerResponse cannot be cast to com.mmall.pojo.User com.mmall.controller.UserController.getUserInfo(UserController.java:58)
同学,这个58行代码及相关代码,都发上来,发的时候注意排版。。。。看你发的这个眼睛快花了。。。
点击这里可以排版,或者在
这里也可以排版。。
看样子是你是直接强转SR对象啦,这个不需要强转,是通过泛型调用sr对象的getData()方法获取到里面实际的数据~~~
012018-04-17 -
陈小舒
2018-04-05
仔细看一下登陆时的session.setAttribute,和获取用户信息的session.getAttribute,看看set和get的是不是同一个对象
00 -
about_blank
2018-03-22
同学你好 看下serverresponse 这个类是否加了序列化的注解
拦截器的配置是否争取呢
022018-03-24
相似问题