spring boot - 如何避免“无法实例化[java.util.List]:指定的类是一个接口”在HTTP控制器处理程序? [英] spring boot - how to avoid "Failed to instantiate [java.util.List]: Specified class is an interface" in HTTP controller handler?

查看:4164
本文介绍了spring boot - 如何避免“无法实例化[java.util.List]:指定的类是一个接口”在HTTP控制器处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的spring boot REST API应用程序中,我需要通过接受强类型列表作为我的输入来处理HTTP POST:

In my spring boot REST API application, I need to handle HTTP POST by accepting a strongly-typed list as my input:

@RestController
public class CusttableController {

    static final Logger LOG = LoggerFactory.getLogger(CusttableController.class);

    @RequestMapping(value="/custtable/update", method=RequestMethod.POST)
    @ResponseBody
    public String updateCusttableRecords(List<Custtable> customers) {
        try {
                for (Custtable cust : customers) {

                Custtable customer = (Custtable) custtableDao.getById(Custtable.class, 
                        new CusttableCompositeKey 
                        (cust.getAccountnum(),cust.getPartition(),cust.getDataareaid()));

在这个API的泽西版中,这个工作得很好,但是使用Spring Boot,它给了我此错误:

In the Jersey version of this API, this worked just fine, but with Spring Boot, it gives me this error:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

在Spring Boot中接受强类型列表的正确方法是什么?

What is the proper way for me to accept a strongly-typed List in Spring Boot?

推荐答案

尝试添加 RequestBody 注释到您的方法定义

Try to add RequestBody annotation to your method definition

@RequestMapping(value="/custtable/update", method=RequestMethod.POST)
@ResponseBody
public String updateCusttableRecords(@RequestBody List<Custtable> customers) {
    //Method body 
}

这篇关于spring boot - 如何避免“无法实例化[java.util.List]:指定的类是一个接口”在HTTP控制器处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆