Servlet.service() for servlet [springmvc] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate **[[Ljava.lang.Object;]: No default constructor found; **nested exception is java.lang.NoSuchMethodException: [Ljava.lang.Object;.()] with root cause
java.lang.NoSuchMethodException: [Ljava.lang.Object;.()
我在做一个网站开发,我希望在Cotroller层中传入Object类型的可变参数,就一直报这个错误,请问该怎么解决呢?以下是我的代码:
//可变参数做查询
//localhost/detailsss/?detail=徐国权&detail=12
@RequestMapping("/detailsss/")
public String queryDetails(Model model,Object...detail){
try {
Object consume = null;
List<Object> list = new ArrayList<>();
for(Object obj : detail){
if(obj instanceof String){
consume = new String(((String) obj).getBytes("iso-8859-1"),"utf-8");
}
else if(obj instanceof Integer){
consume = (int)obj;
}
else if(obj instanceof Date){
consume = (Date)obj;
}
else if(obj instanceof Time){
consume = (Time)obj;
}else{
consume = obj;
}
list.add(consume);
}
//调用service的方法
List<Detailed> details = comsumeService.queryDetails(list);
model.addAttribute("details",details);
return "comsume_info";
} catch (Exception e) {
e.printStackTrace();
return "err";
}
}
Object类不能直接实例化,直接用string类型呗,跟object不是一样嘛
debug看看其他层哪里有问题,这里贴上的代码应该没问题
BeanInstantiationException,说明是初始化bean失败,检查有配置bean的类,比如xml或者@Service @Repository的类有没有写错,报没找到构造函数,有个类是私有构造函数?或者把接口初始化成Bean了?
我终于找到原因了 看,试图找到参数的构造器,失败了没有找到,因为数组是找不到构造器的(并不是Object的原因)
我的天我跟了二十分钟才找到这里!!!