尝试保存到数据库时出错

时间:2015-10-13 06:46:08

标签: spring model-view-controller

我得到了这个错误我不知道我哪里做错了请帮助。提前谢谢:

javax.el.PropertyNotFoundException:Property' message'在org.hibernate.exception.GenericJDBCException类型上不可读     javax.el.BeanELResolver $ BeanProperty.read(BeanELResolver.java:335)     javax.el.BeanELResolver $ BeanProperty.access $ 000(BeanELResolver.java:283)     javax.el.BeanELResolver.getValue(BeanELResolver.java:95)     org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)     org.apache.el.parser.AstValue.getValue(AstValue.java:169)     org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)     org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:936)     org.apache.jsp.WEB_002dINF.views.Error_jsp._jspService(Error_jsp.java:100)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)     org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)     org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)     org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)     javax.servlet.http.HttpServlet.service(HttpServlet.java:648)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

1 个答案:

答案 0 :(得分:0)

基于堆栈跟踪,您试图通过error.jsp上的EL(表达式语言)显示异常的错误消息,可能是这样的:

${exception.message}

正如@dunni指出的,它应该可以工作,因为GenericJDBCException有方法getMessage()。

您可以尝试expicitly调用方法:

${exception.getMessage()}

此异常指出message属性不可读。 您是否将GenericJDBCException作为内部类包装到其他类中,并且可见性不公开,如下所示:

 // note that this is a package-private visible class
 class ExceptionWrapper {
     private Throwable exception;

     public Throwable getException() {
         return exception;
     }
 }

或者像这样:

public class ExceptionWrapper {
     private Throwable exception;

     // note that access is package-private method
     Throwable getException() {
         return exception;
     }
 }

由于您使用的是Spring,因此可以使用其Exception Resolver机制来解决不同类型的异常,如下所示:https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc