I want to configure a Spring Boot Application so that no DB is used at all. So I have annotated my Application class for excluding JPA autoconfig classes:
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {
public static void main(final String... args) {
run(Application.class, args);
}
}
This works fine when the service is run standalone
Unfortunately my test classe seems to ignore the annotation, although I use the Application class for my test
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SwaggerJsonExistenceTest {
...
}
The test fails with the following error message
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot determine embedded database for tests. If you want an embedded database please put a supported one on the classpath.
Update: There are no DB drivers on the classpath.
org.springframework.boot:spring-boot-starter-data-jpa is used for testing (included via testCompile directive in gradle)
How has the test to be configured so that it does not use db-related autoconfiguration?
Fix: I have removed all jpa starter dependencies (as no DB is needed), so that datasource autoconfig is not done at all.