spring-projects / spring-projects/spring-data-commons

Repository lookup can fail in tests when JPMS is used [DATACMNS-1703]

Open
#2,129 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

type: bug
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

László Stahorszki opened DATACMNS-1703 and commented

Let's say I have a project using Spring Data JPA, built by Maven. I have some repository interfaces in org.example.repositories and a manual implementation as well, for let's say MongoDB.

To test my own implementation of the MongoDB repository, I create a test class in org.example.repositories and all tests pass okay.

Now if I'd like to write some integration tests with actual H2 and MongoDB database, my repositories will simply not be found by the PathMatchingResourcePatternResolver.

The reason is that the maven-surefire-plugin patched the test org.example.repositories into the module in my main source, the package has been overridden and the repositories will never be found by classpath scanning anymore. When scanning the org.example.repositories package, the classloader only finds the test class for the MongoDB repository.

A solution to this problem could be brought from JPA. In the persistence.xml there is a tag jar-files which can be set to the output of maven-compile-plugin. Scanning the directory instead of the classpath can work around the fact that patching a module into another overrides the packages instead of merging them


No further details from DATACMNS-1703

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.