[英]How do do slice testing in Spring Boot 1.4 using @DataJpaTest with SpringFox @EnableSwagger2
回復: https : //spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4
我嘗試使用@DataJpaTest測試我的存儲庫,但我的應用程序使用的是Spring,因此使用Springfox @ EnableSwagger2時,測試執行將失敗,並顯示以下錯誤:
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
可以做些什么來解決這個問題? 否則,不可能使用@DataJpaTest進行切片測試。
碼:
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("/")
;
}
}
測試類:
@RunWith(SpringRunner.class)
@DataJpaTest
public class ExchangeRateRepoTest {
@Test
public void doNothing() {
}
}
將@EnableSwagger移出SpringBootApplication
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Configuration
@EnableSwagger2
class AdditionalConfig {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.