启动 GWT/Hibernate 程序时出错
Posted
技术标签:
【中文标题】启动 GWT/Hibernate 程序时出错【英文标题】:Errors when starting a GWT/Hibernate program 【发布时间】:2011-11-23 22:43:39 【问题描述】:我正在尝试制作一个将用户添加到数据库的简单 Web 应用程序。我在 Windows 7 上使用带有 Hibernate、mysql 和 Eclipse IDE 的 GWT-RPC。我通过教程学习了如何使用 Hibernate 在数据库中保存/添加/删除值,以及如何从 @ 执行 GWT-RPC 987654321@。现在,我正在尝试将两者合并到一个非常简单的程序中。
通过 Eclipse 启动应用程序时,出现以下错误:
[WARN] Server class 'org.hibernate.Session' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/D:/enterprize/MyFirstHibernateApp/lib/hibernate3.jar' to the web app classpath for this session
For additional info see: file:/D:/Programs/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.r37v201108301710/gwt-2.4.0/doc/helpInfo/webAppClassPath.html
[WARN] Server class 'org.dom4j.DocumentException' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/D:/enterprize/MyFirstHibernateApp/lib/dom4j-1.6.1.jar' to the web app classpath for this session
For additional info see: file:/D:/Programs/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.r37v201108301710/gwt-2.4.0/doc/helpInfo/webAppClassPath.html
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String rpctest.client.RpctestService.addUser(java.lang.String,java.lang.String) throws java.lang.IllegalArgumentException' threw an unexpected exception: java.lang.ExceptionInInitializerError
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.ExceptionInInitializerError
at hibDomain.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
at hibDomain.HibernateUtil.<clinit>(HibernateUtil.java:7)
at rpctest.server.RpctestServiceImpl.addUser(RpctestServiceImpl.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 22 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at hibDomain.HibernateUtil.buildSessionFactory(HibernateUtil.java:11)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
... 31 more
[ERROR] 500 - POST /rpctest/testService (127.0.0.1) 57 bytes
Request headers
Accept: */*
X-GWT-Permutation: HostedMode
X-GWT-Module-Base: http://127.0.0.1:8888/rpctest/
Content-Type: text/x-gwt-rpc; charset=utf-8
Referer: http://127.0.0.1:8888/Rpctest.html?gwt.codesvr=127.0.0.1:9997
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host: 127.0.0.1:8888
Content-Length: 168
Connection: Keep-Alive
Cache-Control: no-cache
Response headers
Content-Type: text/plain
从堆栈跟踪的最后部分,似乎 SLF4J 库不知何故不可见。但是,我显然在我的路径中有图书馆:
\lib\antlr-2.7.6.jar
\lib\commons-collections-3.1.jar
\lib\dom4j-1.6.1.jar
\lib\hibernate3.jar
\lib\hibernate-cglib-repack-2.1_3.jar
\lib\hibernate-entitymanager-4.0.0.CR5.jar
\lib\javassist-3.4.GA.jar
\lib\jta-1.1.jar
\lib\mysql-connector-java-5.1.18-bin.jar
\lib\slf4j-api-1.6.4.jar
\lib\slf4j-simple-1.6.4.jar
【问题讨论】:
应用程序应该可以正常工作我相信..你没有配置休眠需要的记录器。 【参考方案1】:确保将所有库放入war/WEB-INF/lib
。如果您在其他地方有它们,请先将它们从类路径中删除,移动它们,然后将它们重新添加到类路径中。
【讨论】:
谢谢,这个问题已经解决了,可能是因为编译器现在没有抱怨找不到某些库。虽然现在有新问题,但我认为我最好提出新问题。 你能看到我关于这个应用程序的新问题吗? ***.com/questions/8261514/… @enterprize 我已经看过了,但恐怕我以前没有遇到过这个问题,我不确定出了什么问题。对不起。 我为什么要把库自己放到一些文件夹中——maven 不应该负责这项工作吗?以上是关于启动 GWT/Hibernate 程序时出错的主要内容,如果未能解决你的问题,请参考以下文章