无法加载数据库属性文件。
我database.properties
在类路径资源文件夹中有我的文件,并且我activejdbc.properties
在根目录下进行了配置classpathenv.connections.file=MyProject/src/main/resources/database.properties
我正在使用 mvn 运行我的应用程序:
mvn process-classes
mvn activejdbc-instrumentation:instrument
mvn package
mvn compile exec:java
当我使用 运行应用程序时Base.open()
,出现错误:
org.javalite.activejdbc.DBException: Could not find configuration in a property file for environment: development. Are you sure you have a database.properties file configured?
at org.javalite.activejdbc.DB.open(DB.java:151)
at org.javalite.activejdbc.Base.open(Base.java:52)
at com.soul.seeker.Application.lambda$main$0(Application.java:52)
at spark.FilterImpl$1.handle(FilterImpl.java:62)
at spark.http.matching.BeforeFilters.execute(BeforeFilters.java:48)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:129)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
更新:
从 javalite github 运行示例工作正常,但是,使用spark routing更改它,它的抛出错误:
get("/role_on_login", (req, res) -> {
Base.open();
Person director = new Person("Stephen Spielberg");
director.saveIt();
director.add(new Movie("Saving private Ryan", 1998));
director.add(new Movie("Jaws", 1982));
List data = director.getAll(Movie.class);
Base.close();
return data;
});
错误:
[qtp1213754379-16] WARN org.eclipse.jetty.server.HttpChannel - //localhost:4567/role_on_login
org.javalite.activejdbc.DBException: there is no connection 'default' on this thread, are you sure you opened it?
at org.javalite.activejdbc.DB.connection(DB.java:754)
at org.javalite.activejdbc.DB.createStreamingPreparedStatement(DB.java:521)
at org.javalite.activejdbc.DB.find(DB.java:512)
at org.javalite.activejdbc.LazyList.hydrate(LazyList.java:329)
at org.javalite.activejdbc.AbstractLazyList.toString(AbstractLazyList.java:190)
at spark.serialization.DefaultSerializer.process(DefaultSerializer.java:38)
at spark.serialization.Serializer.processElement(Serializer.java:49)
at spark.serialization.Serializer.processElement(Serializer.java:52)
at spark.serialization.Serializer.processElement(Serializer.java:52)
at spark.serialization.SerializerChain.process(SerializerChain.java:53)
at spark.http.matching.Body.serializeTo(Body.java:72)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:189)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Unknown Source)
所以似乎是一个线程问题,其中 javaliteBase.open()
创建了一个名为“default”的线程,而 spark 无法理解名为“default”的线程