我们有四个application.conf
个文件(application.conf
,application.dev.conf
,application.test.conf
和application.prod.conf
)。所有详细信息都位于主application.conf
文件中,而其他详细信息仅包含db.default
信息(驱动程序,URL,用户和传递)。我们在Play 2框架上使用Java。
我们有一个Global.scala文件,可确保正确的application.conf文件包含在正常的application.conf文件中:
override def onLoadConfig(config: Configuration, path: File, classLoader: ClassLoader, mode: Mode.Mode): Configuration = {
/**
* When the Play application is loaded, depending on which "mode" is set in application.conf (dev, test, or prod),
* that specific configuration file is loaded by this overridden method.
*/
val modeSpecificConfig = config ++ Configuration(ConfigFactory.load(s"application.${mode.toString.toLowerCase}.conf"))
super.onLoadConfig(modeSpecificConfig, path, classLoader, mode)
}
在命令提示符下开始使用play run
后,我想在Eclipse中的JUnit中运行测试,但是遇到配置错误。以上Global.scala中的代码是否在测试执行时运行(在Eclipse中)?如果没有,我怎样才能让测试在Eclipse中正常运行?
其他信息:
我有一个BaseModelTest.java文件,它从application.conf文件中查找“默认”设置(由其他conf文件扩展):
@Before public void dropCreateDb()抛出IOException {
String serverName = "default";
EbeanServer server = Ebean.getServer(serverName);
ServerConfig config = new ServerConfig();
DdlGenerator ddl = new DdlGenerator(); // (SpiEbeanServer) server, new MySqlPlatform(), config);
ddl.setup((SpiEbeanServer) server, new MySqlPlatform(), config);
// Drop
ddl.runScript(false, ddl.generateDropDdl());
// Create
ddl.runScript(false, ddl.generateCreateDdl());
}
我收到的当前配置错误是:
Configuration error: Configuration error[path parameter: Invalid path ' - could not find datasource for default': Token not allowed in path expression: '-' (Invalid number: '-') (you can double-quote this token if you really want it here)]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:92)
at play.api.Configuration.reportError(Configuration.scala:570)
at play.Configuration.reportError(Configuration.java:307)
at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:47)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88)
at scala.collection.immutable.List.foreach(List.scala:318)
at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:88)
at play.api.Play$$anonfun$start$1.apply(Play.scala:88)
at play.api.Play$$anonfun$start$1.apply(Play.scala:88)
at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
at play.api.Play$.start(Play.scala:87)
at play.api.Play.start(Play.scala)
at play.test.Helpers.start(Helpers.java:359)
at models.BaseModelTest.startApp(BaseModelTest.java:70)
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:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.typesafe.config.ConfigException$BadPath: path parameter: Invalid path ' - could not find datasource for default': Token not allowed in path expression: '-' (Invalid number: '-') (you can double-quote this token if you really want it here)
at com.typesafe.config.impl.Parser.parsePathExpression(Parser.java:934)
at com.typesafe.config.impl.Parser.parsePath(Parser.java:974)
at com.typesafe.config.impl.Path.newPath(Path.java:220)
at com.typesafe.config.impl.SimpleConfig.hasPath(SimpleConfig.java:71)
at play.api.Configuration.reportError(Configuration.scala:570)
at play.api.db.BoneCPApi.play$api$db$BoneCPApi$$error(DB.scala:278)
at play.api.db.BoneCPApi$$anonfun$getDataSource$5.apply(DB.scala:426)
at play.api.db.BoneCPApi$$anonfun$getDataSource$5.apply(DB.scala:426)
at scala.Option.getOrElse(Option.scala:120)
at play.api.db.BoneCPApi.getDataSource(DB.scala:426)
at play.api.db.DB$$anonfun$getDataSource$1.apply(DB.scala:142)
at play.api.db.DB$$anonfun$getDataSource$1.apply(DB.scala:142)
at scala.Option.map(Option.scala:145)
at play.api.db.DB$.getDataSource(DB.scala:142)
at play.api.db.DB.getDataSource(DB.scala)
at play.db.DB.getDataSource(DB.java:22)
at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:45)
... 27 more