ActiveJDBC (JavaLite):使用 "activejdbc.properties" 不适用于测试目录
ActiveJDBC (JavaLite) : Using "activejdbc.properties" does not work for test directory
我最近更新到 ActiveJDBC 2.1 以便使用 activejdbc.properties 来外部化数据库 属性 所以我们不必将数据库 username/password 签入SVN。
将“activejdbc.property”文件放入src/main/resources 的主要代码工作完美。现在的目标是替换测试目录下的“database.property”文件src/test/resources 带有“activejdbc.property”,因此它可以指向文件系统上的同一个数据库配置文件。
在测试目录中进行此更改后,我们在执行 gradle 构建(gradle 干净构建)时收到错误。这是我们看到的异常:
`"org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)"
知道为什么这适用于主目录但不适用于测试吗?
堆栈跟踪:
es/main/com/brookdale/model/UnitOfMeasure.class
**************************** 仪器结束 ******************** *********
...
:assemble
:compileTestJava
:processTestResources
:测试类
:测试
com.brookdale.model.ActualChargeTest > unitQuantityMustBeGreaterThanZero FAILED
org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
Caused by:
java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
... more tests ...
com.brookdale.service.RelationshipServiceTest > updateContactRel_GivenValidInfo_
RecordIsInserted FAILED
org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \datab
ase.properties (The system cannot find the file specified)
Caused by:
java.io.FileNotFoundException: \database.properties (The system cannot f
ind the file specified)
49 tests completed, 25 failed, 7 skipped
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
BUILD FAILED`
您似乎没有正确命名文件:文件名不是 activejdbc.property
,而是 activejdbc.properties
。
此外,Java class 加载程序不保证如果在 class 路径上找到多个文件,它们将首先加载哪个文件。如果您想在测试环境中使用不同的 JDBC 属性,请按照此处的文档操作:http://javalite.io/database_connection_management#multiple-environments-property-file-method
下面是这个实现的示例项目:https://github.com/javalite/simple-example/
我最近更新到 ActiveJDBC 2.1 以便使用 activejdbc.properties 来外部化数据库 属性 所以我们不必将数据库 username/password 签入SVN。
将“activejdbc.property”文件放入src/main/resources 的主要代码工作完美。现在的目标是替换测试目录下的“database.property”文件src/test/resources 带有“activejdbc.property”,因此它可以指向文件系统上的同一个数据库配置文件。
在测试目录中进行此更改后,我们在执行 gradle 构建(gradle 干净构建)时收到错误。这是我们看到的异常:
`"org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)"
知道为什么这适用于主目录但不适用于测试吗?
堆栈跟踪: es/main/com/brookdale/model/UnitOfMeasure.class **************************** 仪器结束 ******************** ********* ... :assemble :compileTestJava :processTestResources :测试类 :测试
com.brookdale.model.ActualChargeTest > unitQuantityMustBeGreaterThanZero FAILED
org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
Caused by:
java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
... more tests ...
com.brookdale.service.RelationshipServiceTest > updateContactRel_GivenValidInfo_
RecordIsInserted FAILED
org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \datab
ase.properties (The system cannot find the file specified)
Caused by:
java.io.FileNotFoundException: \database.properties (The system cannot f
ind the file specified)
49 tests completed, 25 failed, 7 skipped
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
BUILD FAILED`
您似乎没有正确命名文件:文件名不是 activejdbc.property
,而是 activejdbc.properties
。
此外,Java class 加载程序不保证如果在 class 路径上找到多个文件,它们将首先加载哪个文件。如果您想在测试环境中使用不同的 JDBC 属性,请按照此处的文档操作:http://javalite.io/database_connection_management#multiple-environments-property-file-method
下面是这个实现的示例项目:https://github.com/javalite/simple-example/