I have a multiple module project with structure:
app/
build.gradle
settings.gradle
app-web/
src/main/java/example/
Application.java
app-repository/
src/main/java/example/
CustomerRepository.java
Customer.java
src/test/java/example/
CustomerRepositoryTest
With Application Class:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
With Repository
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {
}
And Repository Test
@RunWith(SpringRunner.class)
@SpringBootTest
public class CustomerRepositoryTest {
@Autowired
private CustomerRepository repository;
@Test
public void shouldSave() {
// When
final Customer saved = repository.save(new Customer());
// Then
assertThat(saved.getID()).isNotNull();
}
}
Now when I run this test I get the error:
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
This doesnt appear when I have the Application class in my repository module but I need them to be seperated out. What's the best way to get this to work?
If it helps my Spring dependencies are:
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
testCompile("org.springframework.boot:spring-boot-starter-test")
Using the plugin org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE