是否可以让 Sping Data 扫描存储库的单独模块。我已经在一个 maven 模块中创建了一个存储库,并希望从它所依赖的另一个模块中访问它。但是我无法弄清楚配置来告诉它扫描多个模块/jar文件。
在日志中,我看到多个对扫描“核心引擎”的引用,我需要的存储库位于“测试模型”中
DEBUG main - core.io.support.PathMatchingResourcePatternResolver - Searching directory
[<path>\engine\core-engine\target\test-classes\] for files matching pattern
[<path>/engine/core-engine/target/test-classes/**/model/repository/**/*.class]
该项目有许多模块,但在这种情况下只有两个模块会产生影响,它们是“核心引擎”和“测试模型”。“test-model”包含所有配置,即存储库定义、实体和存储库接口。“核心引擎”依赖于“测试模型”。我正在使用 SpringRunner 运行我的测试,并尝试通过将存储库配置 xml 导入单独的“核心引擎”配置来间接引用“测试模型”本身中的 ContextConfiguration,但无济于事。我在使用存储库的“测试模型”模块中运行测试,我的问题只是从“核心引擎”访问这些存储库。
--> test-model (maven module)
---->src/main/java
------>com.test.model.domain (various simple Entities)
------>com.test.model.repository (the repository interfaces)
---->src/main/resources
------>META-INF/datapump/dao-jpa-repository.xml
---->src/test/java
------>com.test.model.domin (various simple CRUD tests using the repositories)
---->src/test/resources
------>META-INF/test-context.xml (defines the Application context and imports dao-jpa-respoitory)
dao-jpa-repository.xml 包含在 test-model 模块中找到并可测试的行
core-engine 依赖于 test-model。
--> core-engine (maven module)
---->src/main/java
------>com.test.model.inject (classes which attempt to use the repositories defined in test-model)
---->src/test/java
------>com.test.model.inject (tests for the above classes)
---->src/test/resources
------>META-INF/test-context.xml (defines the Application context and also imports dao-jpa-respository from the test-model)
从上面我在核心引擎中有一个测试,它试图使用它的存储库从测试模型中持久化一个实体。但是,我无法访问存储库(通过自动装配或手动查找),因为存储库似乎不在上下文中。
如果有人可以提供帮助,我将不胜感激。干杯