How do do slice testing in Spring Boot 1.4 using @DataJpaTest with SpringFox @EnableSwagger2

pumpump :

Re: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4

I tried the @DataJpaTest to test my repository but my application is using Springfox, so with Springfox @EnableSwagger2 the test execution will fail with the following error:

java.lang.IllegalStateException: Failed to load ApplicationContext
...    
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.List<org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping>' available

What can be done to address this? Otherwise, it is impossible to do slice testing using @DataJpaTest.

Code:

Application class:
@SpringBootApplication
@EnableSwagger2
public class CurrencyApplication {
  @Bean
  public Module datatypeHibernateModule() {
    return new Hibernate5Module();
  }

  public static void main(String[] args) {
    SpringApplication.run(CurrencyApplication.class, args);
  }

  @Bean
  public Docket currencyApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build()
        .pathMapping("/")
        ;
  }
}

Test class:

@RunWith(SpringRunner.class)
@DataJpaTest
public class ExchangeRateRepoTest {

  @Test
  public void doNothing() {
  }
}
Dapeng :

Move @EnableSwagger out of the SpringBootApplication

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

@Configuration
@EnableSwagger2
class AdditionalConfig {

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch

How do you configure Embedded MongDB for integration testing in a Spring Boot application?

How to do an integration test for a Spring Boot application?

Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch

How do I externalize configuration with Spring Boot?

How do I debug a request in Spring Boot?

How set SpringFox to show two (or more) versions of the Rest API using Spring Boot?

How do I specify a BeanNamingStrategy with Spring Boot?

How do you connect to H2 as a remote database instead of embedded mode using Spring Boot?

How to do Mapper testing using MRUnit Test?

How do I create a 404 controller using Spring Boot?

Using Spring Boot, how do I see debug info for Zuul?

How do I call the gmail api in Spring Boot 2.x using a service account?

"Column count does not match" for h2 database Select query using projection in Spring-Boot @DataJpaTest

How to do replication with Spring Boot and ActiveMQ Artemis?

How to do integration testing of KStream topology using spring-boot EmbeddedKafka?

Hibernate @Formula not working in Spring boot Tests when using @DataJpaTest

How do I insert data into 2 tables in the same database using Spring Boot Crudrepository?

How to do I deploy a Spring app using Postgresql to Heroku using Spring Boot?

How do I configure Sniffy with Spring Boot?

How do you connect MySQL to Spring Boot?

How do you auto initialize H2 db schema for Spring Boot sessions using JDBC

Failed to update using DataJpaTest spring boot 2.1.0

How to do view Pdf spring Boot

How to do pluggable authentication in Spring Boot JavaConfig?

How to do transaction using aws s3 in Spring Boot

What does springfox do? And how can it be replaced?

How do I use spring @SpringBootTest instead of DataJPATest

Running Spring Boot Tests using @DataJpaTest and @Testcontainers results into ddl exceptions