Spring Data Jpa - scan files in the test folder

I use Data JPA, and this is strange, but it tries to scan (during deployment) test files, which causes an error:

java.lang.ClassNotFoundException: org.junit.runner.RunWith at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) ... WARN : org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor - Failed to classload type while reading annotation metadata. This is a non-fatal error, but certain annotation metadata may be unavailable. 

The class of notfoundexception is that the test dependencies are in the "test" area in maven.

But my question is why is it scanning the test folder? (/ Src / main / test).

The context configuration is as follows:

  <jpa:repositories base-package="com.domain.repository" /> 

Can you tell me what I am doing wrong? The contents of my .classpath are as follows:

 <classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/> ... 

I really appreciate your help with this.

+7
source share
2 answers

But my question is: why does it scan the test folder? (/ Src / main / test) .

The context configuration is as follows:

<jpa:repositories base-package="com.domain.repository" />

To be precise, I don't think Spring scans this folder - this is your source folder after all. It only considers the expanded package structure, and my suspicion will be that the cause of the problem has something to do with it.

I ran into the same problem, but was caused by an erroneous deployment configuration in Eclipse, and not something specific to Spring. I had Eclipse configured to deploy my test classes to src/test/java in the target deployment package, so all the test files (which, of course, had the appropriate package structures) were present when the server started. However, judging by the .classpath you posted, I see that you explicitly exclude them from the deployment.

However, there are other ways that class files can infiltrate your deployment. Have you been able to verify that the test classes are not actually in the deployed package? Can they be synchronized there by another process that you configured (possibly the FileSynch plugin)?

Also, do you have any other Spring context files with configurations for scanning other base packages?

You can add more details about your Eclipse configuration and how you are deploying to your test server to help solve the problem.

+2
source

It seems that the "pseudo function" error in Spring is:

https://jira.springsource.org/browse/SPR-9233

which warns you when it cannot find the class for annotation at runtime, even if your application is ok.

0
source

All Articles