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 ...
随机推荐
- 高博-《视觉SLAM十四讲》
0 讲座 (1)SLAM定义 对比雷达传感器和视觉传感器的优缺点(主要介绍视觉SLAM) 单目:不知道尺度信息 双目:知道尺度信息,但测量范围根据预定的基线相关 RGBD:知道深度信息,但是深度信息对 ...
- 【Win10】页面的导航效果
CommonNavigationTransitionInfo ContinuumNavigationTransitionInfo DrillInNavigationTransitionInfo Ent ...
- getpass
getpass模块用于输入信息时不显示,比如输入密码时隐藏.getpass模块接收用户的输入的数据类型是str类型. #!/usr/bin/env python #-*- coding: utf-8 ...
- 你好,Azure DevOps Server 2019;再见,Team Foundation Server
微软正式发布Azure DevOps Server 2019的第一个版本,作为Team Foundation Server (TFS)2018的升级版本和替代产品. 这是目前市面上唯一一款将产品名称冠 ...
- 【mysql】Windows环境搭建(适用5.7以上)
1 下载MySQL 登录 https://dev.mysql.com/downloads/mysql/ 2 配置 下载好了zip文件,解压至任意非中文目录,在根目录下新建my.ini: 输入以下内容( ...
- bower报错:未能连接到github.com端口1080:超时和一些其他错误
报错1:fatal: unable to access 'https://github.com/xxx/xxxx.git/': Failed to connect to github.com port ...
- BootStrap 4正式版发布(原文翻译)
原文链接:http://blog.getbootstrap.com/2018/01/18/bootstrap-4/ 关于Bootstrap 什么是Bootstrap Bootstrap,来自 Twit ...
- f.lux在linux下的安装和使用
安装还是蛮容易的~只是装完后在白天色温没什么变化就一直以为没有装成功 https://justgetflux.com/linux.html 这里下载,解压后 安装好以后xflux -l (经纬度) 就 ...
- “全栈2019”Java多线程第十八章:同步代码块双重判断详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- Navicat 12破解工具 +安装包
下载地址: https://www.lanzous.com/b657322/ 密码:1j9x zip解压密码:gubin 下载完成 是这样的 先安装第一个 安装完成后 不要打开 ,把第二个复制到安 ...