Failed to instantiate [java.util.List]: Specified class is an interface
错误信息提示:
Failed to instantiate [java.util.List]: Specified class is an interface;
错误信息意思:参数错误,参数封装出了问题。
原因:
前端给后台传递了一个list对象,本来以为直接用list 可以接收,但是运行方法报错,参数错误。查询错误问题,发现是前端传递的对象,后台没有set,get的实体接收。
controller中参数List内封装的不是基本数据类型,而是一个对象,springMVC源码获取前台的参数是:request.getParameter(" ")来接收参数的,这样的话,封装参数时就出问题了。
解决办法:
第一种方法:
将VO对象再进行封装。
import java.util.List;
public class ConfigListForm {
private List<Config> ConfigList;
public List<<span style="font-family:Arial, Helvetica, sans-serif;">Config</span>> getConfigList() {
return ConfigList;
}
public void setConfigList(List<Config> configList) {
ConfigList = configList;
}
}
缺陷:
这种方式不好处理接收的数据。我想接受的数据是config对象的数组,但是接收的数据是:[{configName=111, configId=111},{configName=222, =222}],不能自动封装到我的对象里,没有把configName,configId,封装到Config对象中。
第二种方法:
可以把数组序列化成Json字符串提交,后台springmvc里用@ RequestBody String 方式接收,然后把这个接收到的json串用json工具转换为数组,这样就解决了springmvc不能绑定对象数组的问题了。
将对象数组用{"list":JSON.stringify(array)}绑定到后台,后台用@RequestBody String configs接收,接收的是json数据,然后用jackson把configs转为数组List<configs> configList。
<span style="font-family:'宋体', Arial, Helvetica, 'san-serif';">var configList= JSON.stringify([
{configName: "sgs-demo", configId: "1"},
{configName: "sgs-demo-1", configId: "2"}
]); $.ajax({
type: "post",
url: "/config",
data:</span><span style="font-family:SimSun;"><span style="font-size:14px;line-height:25.2px;background-color:rgb(250,250,250);">c</span><span style="font-size:14px;line-height:25.2px;background-color:rgb(250,250,250);">onfigs</span></span><span style="font-family:'宋体', Arial, Helvetica, 'san-serif';"> ,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response, ifo) {
alert("success");
}, error: function () {
alert("error");
}
}) </span>
dataType:'json',//预期的服务器响应的数据类型。
contentType: "application/json; charset=utf-8",//发送数据到服务器时所使用的内容类型。默认是:"application/x-www-form-urlencoded"。
controller层
@RequestMapping(value = "/config", method = RequestMethod.POST)
public void myDomain(HttpServletRequest request, @RequestBody String configs) throws Exception{ ObjectMapper objectMapper = new ObjectMapper();
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, configs.class);
List<configs> list = objectMapper.readValue(configs, javaType); System.out.println("");
}
第三种方法:spring3.2 直接支持泛型集合
spring 3.2 直接支持泛型集合,如List<Sample> Map<String, Sample>等集合泛型
具体步骤
1 要配置驱动注解<mvc:annotation-driven/> ,里面注册了会把json绑定到list的"Bean实例"。
2 前台传json数组,后台直接@RequestBody List<Config> list接收就可以。
(这种方法还没测试过,只是在查这个问题的时候看到这种方式。)
Failed to instantiate [java.util.List]: Specified class is an interface的更多相关文章
- 【spring mvc】后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate ...
- Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause
最近项目中页面比较复杂,springMVC传参过程中遇到这样一个错误:Could not instantiate bean class [java.util.List]: Specified clas ...
- BeanInstantiationException: Failed to instantiate [java.time.LocalDateTime]
错误提示: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationExce ...
- 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component
自己写了个最简单的springMVC项目练练手,没有用maven,在WebContent中新建了lib文件夹,将jar包复制到这里面,然后add to build path到项目里. 启动Tomcat ...
- Maven使用tomcat7-maven-plugin插件run时出现错误: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component
错误如下: A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catal ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]
本文为博主原创,未经允许不得转载: 被坑了好长时间的bug,差点就要重新配置环境,重新下载,重新开始的境遇.在此记录一下: 首先展示一下报错的异常: -Apr- ::] org.apache.cata ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xiaozao_web]]
二月 20, 2017 11:30:28 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRul ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component...
今天开发犯了一个特lowB的错,记录下来,引以为戒! 严重: A child container failed during start java.util.concurrent.ExecutionE ...
- java.util.concurrent.ExecutionException
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
随机推荐
- Django 必会面试题总结
1 列举Http请求中常见的请求方式 HTTP请求的方法: HTTP/1.1协议中共定义了八种方法(有时也叫“动作”),来表明Request-URL指定的资源不同的操作方式 注意: 1)方法名称是 ...
- Oracle之SQL语句性能优化(34条优化方法)
(1)选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处 ...
- web service 项目 和 普通 web项目 的 区别
web service 面向的是开发者(需要再次开发) 普通web 面向的是用户(直接使用)
- Nvidia显卡驱动下载
https://www.nvidia.cn/Download/index.aspx?lang=cn https://blog.csdn.net/weixin_39643690/article/deta ...
- Ubuntu安装教程(双系统)
经常要重装还不如写个安装教程省的每次都要查 Ubuntu安装教程: win7下安装Linux实现双系统全攻略:https://jingyan.baidu.com/article/c275f6bacc3 ...
- Oracle EBS打补丁
http://hutianci.iteye.com/blog/1457287 l例子: 打 Patch# 11843100:R12.CAC.B 打PATCH之前先查询一下是否已经有了这个PATCH ...
- [LeetCode 题解] Spiral Matrix
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 题目链接 54. Spiral Matrix ...
- C++ 补遗
C++通过引用传递数组 数组形参可以声明为数组的引用.如果形参是数组的引用,编译器不会将数组实参转化为指针,而是传递数组的引用本身. 在这种情况下,数组大小成为形参和实参类型的一部分(实参长度与形参长 ...
- vux组件简单使用请大佬指点
一.打开vux项目 我用的是vsCode工具自己找看个人选择,第一次使用请去找vc方便开发使用的插件 二.项目目录及文件,有遮挡部分自行查看文件 三.根据官方文档实现引入插件 通过vux-loader ...
- ASP.NET Core SignalR CORS 跨域问题
将 SignalR 集成到 ASP.NET Core api 程序的时候,按照官方 DEMO 配置完成,本地访问没有问题,但是发布之后一直报跨域问题,本地是这样设置的: 原始代码: services. ...