一、问题
SpringBoot运行时,报下面错误!!!
Error creating bean with name 'com.xz.bean.User': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xz.bean.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.xz.bean.User.<init>()
二、解决
看报错的信息,可知:实例化对象时报错。并且:No default constructor found,没有找到默认的构造器。这是就要看自己的实体类里面有没有无参构造。没有,则加上即可。
- 根据spring的bean的生命周期可知,调用无参构造创建对象,没有的话,自然就报错