GWT服务器应用程序无法连接到数据库

时间:2014-04-09 20:58:36

标签: java gwt jdbc torque

我在服务器端有一个基本服务,它只是在表上查找。该代码在隔离的代码/ JUnit测试中工作正常。

当我将它集成到服务器端时,我得到一个异常:

org.apache.torque.TorqueException: Torque is not initialized
    at org.apache.torque.TorqueInstance.getConnection(TorqueInstance.java:824)
    at org.apache.torque.Torque.getConnection(Torque.java:290)
    at org.apache.torque.util.Transaction.beginOptional(Transaction.java:106)
    at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:651)
    at org.simmental.datamods.om.BaseAcctPeer.doSelectVillageRecords(BaseAcctPeer.java:527)
    at org.simmental.datamods.om.BaseAcctPeer.doSelectVillageRecords(BaseAcctPeer.java:501)
    at org.simmental.datamods.om.BaseAcctPeer.doSelect(BaseAcctPeer.java:397)
    at org.redangus.dao.services.AccountServices.getAccountByPrefix(AccountServices.java:15)
    at org.redangus.signup.server.HerdPrefixValidationServiceImpl.validatePrefixServer(HerdPrefixValidationServiceImpl.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:68)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:370)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:744)

它看起来很像Google AppEngine的一些问题,但它并没有在我的环境中激活。

我激活GAE,看看会发生什么,我得到了:

java.lang.NoClassDefFoundError: org/apache/torque/TorqueException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
    at java.lang.Class.getConstructor0(Class.java:2803)
    at java.lang.Class.newInstance(Class.java:345)
    at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
    at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)

[..]

Caused by: java.lang.ClassNotFoundException: org.apache.torque.TorqueException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:216)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 42 more

这完全有道理......

当我回到没有AppEngine时,它仍然失败,就像我的第一个例子一样。

我不想在AppEngine上运行我的代码,这只是一个测试。

我不认为Torque实际上在做任何不好的事情......

2 个答案:

答案 0 :(得分:0)

AppEngine错误似乎表明Torque不在您的WEB-INF/lib

答案 1 :(得分:0)

好的,这是一种奇怪的情况,但是:

  • 当我在命令行中使用代码时,数据库无法启动。

  • 当我在GWT中使用相同的代码时,我不得不在代码中通过Database.start()对其进行初始化。

所以,我一无所知地责备AppEngine :)。