![](/img/trans.png)
[英]spring MVC3 errors Could not instantiate bean class [java.util.List]: Specified class is an interface Occasional
[英]spring boot - how to avoid “Failed to instantiate [java.util.List]: Specified class is an interface” in HTTP controller handler?
在我的spring boot REST API應用程序中,我需要通過接受強類型列表作為我的輸入來處理HTTP POST:
@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的Jersey版本中,這個工作得很好,但是使用Spring Boot,它給了我這個錯誤:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
在Spring Boot中接受強類型列表的正確方法是什么?
嘗試將RequestBody注釋添加到方法定義中
@RequestMapping(value="/custtable/update", method=RequestMethod.POST)
@ResponseBody
public String updateCusttableRecords(@RequestBody List<Custtable> customers) {
//Method body
}
對我來說,我在一個列表中意外地將一個類包裝成了一個錯字。 刪除拼寫錯誤允許序列化通過spring data rest + jackson正確發生。
List<MyClass> a; // typo
MyClass = a;// fix
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.