pum*_*ump 5 java spring spring-boot springfox
回复: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
Run Code Online (Sandbox Code Playgroud)
可以做些什么来解决这个问题?否则,不可能使用@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("/")
;
}
}
Run Code Online (Sandbox Code Playgroud)
测试类:
@RunWith(SpringRunner.class)
@DataJpaTest
public class ExchangeRateRepoTest {
@Test
public void doNothing() {
}
}
Run Code Online (Sandbox Code Playgroud)
Dap*_*eng 13
将@EnableSwagger移出SpringBootApplication
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Configuration
@EnableSwagger2
class AdditionalConfig {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1455 次 |
| 最近记录: |