ObjectifyService.begin()引发IllegalStateException

时间:2019-01-16 11:37:31

标签: java maven google-app-engine google-cloud-datastore objectify

我正在尝试将google cloud数据存储区用于我的maven项目,但遇到了一些麻烦。

执行时

Consumer consumer=new Consumer(username+password,username,password,name,email) {
    ofy().save().entity(consumer).now(); }

它在

ObjectifyFilter.class 中停止
try (Closeable closeable = ObjectifyService.begin()) {   ..

它会抛出

  

java.lang.IllegalStateException在   com.google.appengine.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:443)     在   com.google.appengine.api.datastore.DatastoreServiceGlobalConfig $ Builder.build(DatastoreServiceGlobalConfig.java:233)     在   com.google.appengine.api.datastore.DatastoreServiceGlobalConfig.fromEnv(DatastoreServiceGlobalConfig.java:311)     在   com.google.appengine.api.datastore.DatastoreServiceGlobalConfig.getConfig(DatastoreServiceGlobalConfig.java:47)     在   com.google.appengine.api.datastore.DatastoreServiceFactoryImpl.getAsyncDatastoreService(DatastoreServiceFactoryImpl.java:19)     在   com.google.appengine.api.datastore.DatastoreServiceFactoryImpl.getAsyncDatastoreService(DatastoreServiceFactoryImpl.java:9)     在   com.google.appengine.api.datastore.DatastoreServiceFactory.getAsyncDatastoreService(DatastoreServiceFactory.java:32)     在   com.googlecode.objectify.ObjectifyFactory.createRawAsyncDatastoreService(ObjectifyFactory.java:133)     在   com.googlecode.objectify.ObjectifyFactory.createAsyncDatastoreService(ObjectifyFactory.java:121)     在   com.googlecode.objectify.impl.ObjectifyImpl.createAsyncDatastoreService(ObjectifyImpl.java:246)     在   com.googlecode.objectify.impl.ObjectifyImpl.createWriteEngine(ObjectifyImpl.java:257)     在   com.googlecode.objectify.impl.SaverImpl.entities(SaverImpl.java:60)     在com.googlecode.objectify.impl.SaverImpl.entity(SaverImpl.java:35)     在it.units.view.ConsumerView.createConsumer(ConsumerView.java:43)     在it.units.controller.login.processRequest(login.java:45)处   it.units.controller.login.doPost(login.java:92)位于   javax.servlet.http.HttpServlet.service(HttpServlet.java:707)在   javax.servlet.http.HttpServlet.service(HttpServlet.java:790)在   org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1623)     在   com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.tools.development.jetty9.StaticFileFilter.doFilter(StaticFileFilter.java:123)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)     在   com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)     在   com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1610)     在   com.google.appengine.tools.development.DevAppServerRequestLogFilter.doFilter(DevAppServerRequestLogFilter.java:44)     在   org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1602)     在   org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)     在   org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)     在   org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)     在   org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)     在   org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)     在   org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)     在   org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)     在   org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)     在   org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)     在   com.google.appengine.tools.development.jetty9.DevAppEngineWebAppContext.doScope(DevAppEngineWebAppContext.java:94)位于   org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)     在   org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)     在   com.google.appengine.tools.development.jetty9.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:595)     在   org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)     在org.eclipse.jetty.server.Server.handle(Server.java:502)处   org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)在   org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)     在   org.eclipse.jetty.io.AbstractConnection $ ReadCallback.succeeded(AbstractConnection.java:305)     在org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)     在   org.eclipse.jetty.io.ChannelEndPoint $ 2.run(ChannelEndPoint.java:118)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)     在   org.eclipse.jetty.util.thread.ReservedThreadExecutor $ ReservedThread.run(ReservedThreadExecutor.java:366)     在   org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)     在   org.eclipse.jetty.util.thread.QueuedThreadPool $ 2.run(QueuedThreadPool.java:683)     在java.lang.Thread.run(Thread.java:748)

实体注册操作通过。服务器启动时发生:

public void contextInitialized(ServletContextEvent event) {

    ObjectifyService.register(Consumer.class);
    ObjectifyService.register(Administrator.class);
    ObjectifyService.register(Uploader.class);
    ObjectifyService.register(File.class);
}

,但是之后,我无法可视化数据存储中的实体。我应该看他们吗? (我确定它确实注册了操作,我在调试模式下进行了检查)

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

该异常已从Appengine SDK中排除-看起来像是某种配置问题。它应该包含解释该问题的异常消息。

注册实体对数据存储中的数据不执行任何操作。它仅在应用程序VM中配置软件。数据存储区显示您已保存的实体-请记住,它几乎是无模式的;您可以随时创建任意种类。

也许可以退后一步并实施快速调试以熟悉环境。跳过Objectify秒钟,然后编写一个使用低级API(DatastoreServiceFactoryDatastoreService)的应用程序,以将一个简单的测试实体写入数据存储区。一旦可行(验证配置),然后继续使用Objectify。

答案 1 :(得分:0)

感谢您的帮助!我通过添加

解决了
java.sql.SQLException: No suitable driver found for 
jdbc.mysql://localhost:3306/demo
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at jdbcdemo.Driver.main(Driver.java:12)