Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause(

Posted Mr. Ma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 class is an interface] with root cause

经研究发现这是参数封装出了问题。

还原代码:

@RequestMapping("/test")
    public ModelAndView test(List<OptionVo> ov){
        ModelAndView view = new ModelAndView("list");
        return view;
    }

VO对象:

public class OptionVo {

	private String name;
	private String options;
	private List<String> option;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOptions() {
		return options;
	}

	public void setOptions(String options) {
		this.options = options;
	}

	public List<String> getOption() {
		return option;
	}

	public void setOption(List<String> option) {
		this.option = option;
	}
}

  可以看出,controller中参数List内封装的不是基本数据类型,而是一个对象,springMVC源码获取前台的参数是:request.getParameter("")来接收参数的,这样的话,封装参数时就出问题了。

解决办法:

将VO对象再进行封装:

public class Form {
    private List<OptionVo> o;

    public List<OptionVo> getO() {
        return o;
    }

    public void setO(List<OptionVo> o) {
        this.o = o;
    }
}

controller:

@RequestMapping("/test")
    public ModelAndView test(Form formm){
        ModelAndView view = new ModelAndView("list");
        return view;
    }

前台页面:

<input type="text" name="o[0].name" value="爱好">
        <input type="text" name="o[0].options" value="爱好">
        <input type="hidden" name="o[0].option" value="1">
        <input type="hidden" name="o[0].option" value="2">
        <input type="hidden" name="o[0].option" value="3">
        <input type="hidden" name="o[0].option" value="4">
        <hr>
        <input type="text" name="o[1].name" value="哈哈">
        <input type="text" name="o[1].options" value="爱好2">
        <input type="hidden" name="o[1].option" value="1">
        <input type="hidden" name="o[1].option" value="2">
        <input type="hidden" name="o[1].option" value="3">
        <input type="hidden" name="o[1].option" value="4">
        <hr>
View Code

 

以上是关于Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause(的主要内容,如果未能解决你的问题,请参考以下文章

org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.brid

Rendering Problems The following classes could not be instantiated

解决方案-Rendering Problems-The following classes could not be instantiated:

AndroidAndroidStudio开发工具布局xml文件不显示视图。提示:The following classes could not be instantiated:

'org.springframework.jdbc.uncategorizedSQLException 'could not be instantiated (用的是Ibatis)

org.apache.cxf.interceptor.Fault: Could not instantiate service class com.mangoubiubiu.cxf.test.Hell