[英]Running Spring integration tests with @NoRepositoryBean with no @Repository implementation
I have a situation where I have a few modules, with the primary module being datastore agnostic. 我遇到的情况是我有几个模块,而主要模块与数据存储区无关。 There are child modules that depend on the primary module with repository implementations for JPA and Mongo.
有一些子模块依赖于主模块以及JPA和Mongo的存储库实现。
Core-Module
- All business logic, @NoRepositoryBean
interfaces Core-Module
-所有业务逻辑, @NoRepositoryBean
接口 Core-Mongo
- Dependent on Core-Module
with Mongo repositories/domain Core-Mongo
依赖于具有Mongo存储库/域的Core-Module
Core-JPA
- Dependent on Core-Module
with JPA repositories/domain Core-JPA
依赖于具有JPA存储库/域的Core-Module
Essentially, what I'd like to do is have integration tests in Core-Module
use an H2 database to perform the tests and not be dependent on a @Repository
implementation. 本质上,我想做的是在
Core-Module
进行集成测试,使用H2数据库执行测试,而不依赖于@Repository
实现。
I realize I could make test-only @Repository
interfaces, and that may be the route I have to go, but I'm wondering if there's a simpler way. 我意识到我可以制作仅测试的
@Repository
接口,这也许是我必须走的路,但是我想知道是否有更简单的方法。 Essentially, is there a way to "instantiate" a @NoRepositoryBean
in tests or some other simple way to do this without having to declare test only repositories? 本质上,是否有一种方法可以在测试中“实例化”
@NoRepositoryBean
或其他一些无需声明仅测试存储库的简单方法?
I just checked this interest question. 我刚刚检查了这个兴趣问题。 I marked in my test project
UserRepository
by @NoRepositoryBean
, after that in test i unable to autowired it. 我在测试项目
UserRepository
了@NoRepositoryBean
,之后在测试中我无法对其进行自动@NoRepositoryBean
。 But in documentation spring-docs i found java creation repositories process description, and it's works perfect. 但是在文档spring-docs中,我发现了Java创建存储库过程描述,并且它的工作原理很完美。 Just before test create required repositories.
在测试之前,创建所需的存储库。 Piece of test code example:
一段测试代码示例:
private UserRepository userRepository;
@Autowired
private EntityManager entityManager;
@Before
public void init() {
JpaRepositoryFactory factory = new JpaRepositoryFactory(entityManager);
userRepository = factory.getRepository(UserRepository.class);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.