0

我最近更新到 ActiveJDBC 2.1,以便使用 activejdbc.properties 来外部化数据库属性,这样我们就不必将数据库用户名/密码签入 SVN。

将主代码的“ activejdbc.property ”文件放在src/main/resources中效果很好。现在的目标是将测试目录src/test/resources中的“ database.property ”文件替换为“ activejdbc.property ”,这样它就可以指向文件系统上相同的数据库配置文件。

在测试目录中进行此更改后,我们在执行 gradle build (gradle clean build) 时收到错误。这是我们看到的异常:

`"org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (系统找不到指定的文件)"

任何想法为什么这适用于主目录但不适用于测试?

堆栈跟踪:es/main/com/brookdale/model/UnitOfMeasure.class **************************** END INSTRUMENTATION ***** *********************** ... :assemble :compileTestJava :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`
4

1 回答 1

0

看来您没有正确命名文件:文件名不是activejdbc.property,而是activejdbc.properties.

此外,Java 类加载器不保证如果在类路径中找到多个文件,它们将首先加载哪个文件。如果您想在测试环境中使用不同的 JDBC 属性,请按照此处的文档操作:http: //javalite.io/database_connection_management#multiple-environments-property-file-method

这是具有此实现的示例项目:https ://github.com/javalite/simple-example/

于 2018-03-01T20:56:50.093 回答