求助,手机请求后台数据的时候出现org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface错误,后台用的是Spring框架,手机端用的retrofit ,而且代码中的List已经改成了JSON字符串
.....看着就知道你是要把数据反序列化成接口吧...想什么呢.
是类,不是接口,这是我Controller
@Controller @RequestMapping("shoppingcart") public class ShoppingCartController { @Autowired private ShoppingCartService shoppingCartService; @RequestMapping("addshoppingcart") @ResponseBody public boolean addShoppingCartGood(@RequestBody ShoppingCartGood shoppingCartGood,String buyerUserId){ boolean isAddShoppingCartSuccess=shoppingCartService.addGoodToCart(shoppingCartGood, buyerUserId); return isAddShoppingCartSuccess; } @RequestMapping("findshoppingcart") @ResponseBody public List<ShoppingCartGood> findShoppingCartGood(String buyerUserId,int page,int size){ List<ShoppingCartGood> shoppingCartGoodList=shoppingCartService.queryShoppingCartGood(buyerUserId, page, size); return shoppingCartGoodList; } @RequestMapping("deleteshoppingcart") @ResponseBody public boolean deleteShoppingCartGood(String shoppingCartGoodIdJSON){ boolean isDeleteSuccess=shoppingCartService.deleteCartGood(shoppingCartGoodIdJSON); return isDeleteSuccess; } }
下面是我的类
public class ShoppingCartGood extends Good{ private int storeId; //商店Id private int goodNumber; //商品数量 public ShoppingCartGood() { super(); } public ShoppingCartGood(int storeId, int goodNumber) { super(); this.storeId = storeId; this.goodNumber = goodNumber; } public int getStoreId() { return storeId; } public void setStoreId(int storeId) { this.storeId = storeId; } public int getGoodNumber() { return goodNumber; } public void setGoodNumber(int goodNumber) { this.goodNumber = goodNumber; } }
而且,我在Controller中是直接把数据传递过去,断点的时候是Controller不走,三个方法中中间的那个是没有问题的,第一个第三个不行
@软件杨威: 前面抛出的异常还是后台抛出的异常.异常在哪一行.
@吴瑞祥: 手机端直接返回到上一界面,后台报的这个错误,没有说是哪一行
@软件杨威: 打日志吧.先定位异常在哪一行再解决.
@吴瑞祥:
严重: Servlet.service() for servlet [mvc] in context with path [/FreeUniversityServer] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface] with root cause org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:99) at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:142) at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:80) at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:102) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
这是我的错误,后台直接是不走这个方法,前台是封装的retrofit,结果的response的body直接是null,
@软件杨威: 把ShoppingCartGood这个类改成poco看看咯.或者改个返回值看看.是不是这个类型有问题.
@吴瑞祥: 我再改改这个类试试,返回值改过没用
一个错误出现在这儿很无奈,搞了很长时间,JSON的jar包没有导全,全导进去之后就好了