Re: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4
I tried @DataJpaTest to check my repository, but my application uses Springfox, so using Springfox @ EnableSwagger2, the test will fail:
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 solve this problem? Otherwise, it is not possible to perform slice testing with @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("/") ; } }
Testing Class:
@RunWith(SpringRunner.class) @DataJpaTest public class ExchangeRateRepoTest { @Test public void doNothing() { } }
source share