Java创建一个异常long_错误:java.lang.NoSuchMethodException:java.lang.Long。()在春季MVC中...

从数据库读取学生对象时出现此错误。

org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.()

org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107)

全栈跟踪:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.()

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)

org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)

javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.()

org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:775)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:368)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:172)

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)

org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)

org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)

org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)

javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NoSuchMethodException: java.lang.Long.()

java.lang.Class.getConstructor0(Class.java:3082)

java.lang.Class.getDeclaredConstructor(Class.java:2178)

org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:775)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:368)

org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:172)

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)

org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)

org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)

org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)

javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

学生.java

@Entity

@Table(name="Student")

public class Student implements Serializable{

private static final long serialVersionUID = 1L;

@Id

@GeneratedValue(strategy=GenerationType.AUTO)

@Column(name="studentId")

Long studentId;

@Column(name="studentName")

String studentName;

Controller.java

@RequestMapping(value = "/read.html")

public String readStudent(Model model, @ModelAttribute("studentId") Long studentId) {

Student student = null;

studentId = 2l;

try{

student = serviceFile.readStudent(studentId);

}catch(Exception e){

model.addAttribute("message", "Some thing went wrong !!!! Exception occoured");

return "message";

}

model.addAttribute("student", student);

return "read";

}

daoImpl.java

@Repository

@Transactional

public class DaoImplFile implements DaoFile {

private EntityManager entityManager;

public EntityManager getEntityManager() {

return entityManager;

}

@PersistenceContext

public void setEntityManager(EntityManager entityManager) {

this.entityManager = entityManager;

}

@Override

public Student read(Long studentId) throws NullPointerException {

Student student = entityManager.find(Student.class, studentId);

if (student!=null) {

return student;

} else {

return null;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值