Spring Boot + Springbox swagger error(Spring Boot + Springbox 招摇错误)
问题描述
我有一个spring boot项目想通过springbox与swagger集成.
I have a spring boot project want to integrate with swagger via springbox.
我的 Spring Boot 应用程序启动并运行良好.
I have my spring boot app up and running all good.
但是我添加了springbox后,它无法通过单元测试.
However after I added springbox, it can not pass unit test.
这是我在项目中添加的详细信息.
Here are the details I added in project.
对于pom.xml
,添加
<!--Swagger io for API doc-->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
然后用一个大摇大摆的配置类
then with a swagger config class
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket booksApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/.*"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("blah")
.description("blah.")
.termsOfServiceUrl("http://www.blah.com.au")
.contact("blah")
.build();
}
}
我在运行 mvn clean package
时遇到的错误是
The error I am getting when run mvn clean package
is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/Users/jasonfeng/.m2/repository/io/springfox/springfox-spring-web/2.2.2/springfox-spring-web-2.2.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.util.List]: : No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] found for dependency [collection of org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] found for dependency [collection of org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
我使用的版本是
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
推荐答案
一直在研究这个问题有一段时间没有运气,然后发布了这个问题.刚刚发布问题后,我找到了解决方案......(我责怪早上咖啡不太好)
Been looking into this problem for the while morning without luck, then posted this question. Just after posted the question, I found out the solution for this..... (I blame on the not-so-good morning coffee)
只需去掉swagger配置类中的@Configuration
注解即可.
Simply remove the @Configuration
annotation in the swagger configuration class.
这是我参考的链接
https://github.com/springfox/springfox/issues/462
这篇关于Spring Boot + Springbox 招摇错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring Boot + Springbox 招摇错误
基础教程推荐
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01