Indeed, Spring Boot is really customizable for the most part. You can probably get rid of the large amount of code that you published, especially in Application .
I would like you to include the package names of all your classes, or at least the ones that were for Application and JpaTest . The point with @DataJpaTest and several other annotations is that they look for the @SpringBootConfiguration annotation in the current package, and if they cannot find it there, they cross the package hierarchy until they find it.
For example, if the full name for your test class was com.example.test.JpaTest and one for your application was com.example.Application , then your test class could find @SpringBootApplication (in this case @SpringBootConfiguration ).
If the application was in a different branch of the package hierarchy, however, like com.example.application.Application , it would not find it.
Example
Consider the following Maven project:
my-test-project +--pom.xml +--src +--main +--com +--example +--Application.java +--test +--com +--example +--test +--JpaTest.java
And then the following content in Application.java :
package com.example; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
The following are the contents of JpaTest.java :
package com.example.test; @RunWith(SpringRunner.class) @DataJpaTest public class JpaTest { @Test public void testDummy() { } }
Everything should work. If you create a new folder inside src/main/com/example called app and then place its Application.java inside it (and update the package declaration inside the file), running the test will give you the following error:
java.lang.IllegalStateException: Unable to find @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest (classes = ...) with your test
Thomas Kåsene Aug 22 '16 at 16:56 2016-08-22 16:56
source share