我最近更新为ActiveJDBC 2.1,以便使用activejdbc.properties将数据库属性外部化,因此我们不必将数据库用户名/密码签入SVN。
将"activejdbc.property“文件放入src/main/resources中,作为主要代码,效果很好。现在的目标是将测试目录src/test/resources中的src/test/resources文件替换为"activejdbc.property“,这样它就可以指向文件系统上的相同数据库配置文件。
在测试目录中进行此更改后,我们在执行gradle构建(gradle干净构建)时会收到一个错误。这是我们看到的例外:
“org.javalite.activejdbc.InitException: java.io.FileNotFoundException:\database.properties (系统找不到指定的文件)”
知道为什么这对主目录有效,而不适用于测试吗?
es/main/com/brookdale/model/UnitOfMeasure.class *结束检测*.:汇编:编译程序test :processTestResources :testClasses :test
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`发布于 2018-03-01 20:56:50
您似乎没有正确命名该文件:该文件的名称不是activejdbc.property,而是activejdbc.properties。
此外,如果Java类加载器在类路径上找到多个文件,则不能保证它们将首先加载哪个文件。如果您希望在您的测试环境中使用不同的JDBC属性,请在这里遵循docs:management#multiple-environments-property-file-method
下面是一个具有此实现的示例项目:https://github.com/javalite/simple-example/
https://stackoverflow.com/questions/49058268
复制相似问题