Failed to instantiate [java.util.List]: Specified class is an interface
来源:互联网 发布:网络的安全 编辑:程序博客网 时间:2024/05/16 09:13
错误信息提示:
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<Config> 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。
var configList= JSON.stringify([ {configName: "sgs-demo", configId: "1"}, {configName: "sgs-demo-1", configId: "2"} ]); $.ajax({ type: "post", url: "/config", data:configs , contentType: "application/json; charset=utf-8", dataType: "json", success: function (response, ifo) { alert("success"); }, error: function () { alert("error"); } })
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
- 关于运行期异常:Failed to instantiate [java.util.List]: Specified class is an interface
- 关于运行期异常:Failed to instantiate [java.util.List]: Specified class is an interface
- 解决Failed to instantiate [java.util.List]: Specified class is an interface问题
- SpringMvc报错解决:Failed to instantiate [java.util.List]: Specified class is an interface
- Failed to instantiate [java.util.List]: Specified class is an interface
- 解决Failed to instantiate [java.util.List]: Specified class is an interface问题
- 错误:Could not instantiate bean class [java.util.List]: Specified class is an interface
- Could not instantiate bean class [java.util.List]: Specified class is an interface
- Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
- Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
- springMVC接受list报错:Could not instantiate bean class [java.util.List]: Specified class is an interf
- Specified class is an interface
- Specified class is an interface
- mybatis报错:Could not instantiate bean class [Dao.stuDao]: Specified class is an interface
- Could not instantiate bean class [javax.servlet.ServletContext]: Specified class is an interface
- Mybatis,Specified class is an interface
- springboot Mapper: Specified class is an interface
- 压缩解压缩的相关命令
- 错误总结之maven之compile:非法字符: \65279
- MySQL企业常见架构与调优经验分享
- Keli5 打开Cypress CY7C68013A(51单片机)官方开发包例程
- 搜狗输入法不能正常使用?
- Failed to instantiate [java.util.List]: Specified class is an interface
- long, double类型的大小端处理
- LeetCode 264. Ugly Number II
- JavaScript的作用域,作用域链,变量
- 临时指定pip源路径,无需配置pip源
- Panabit专业流量监控开源软件
- Linux线程qps测试
- 01 Matrix解题报告
- ios加密、编码方式汇总