小编典典

Spring Boot + Springbox摇晃错误

spring-boot

我有一个Spring Boot项目想要通过springbox与swagger集成。

我已经启动了我的spring boot应用程序,并且运行良好。

但是,在我添加springbox之后,它无法通过单元测试。

这是我在项目中添加的详细信息。

对于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>

然后用招摇的配置类

@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

  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>

阅读 358

收藏
2020-05-30

共1个答案

小编典典

在没有运气的情况下一直在调查这个问题,然后发布了这个问题。在发布问题之后,我就找到了解决方法.....(我怪罪于不太好的早晨咖啡)

只需@Configuration在swagger配置类中删除注释。

这是我指的链接

https://github.com/springfox/springfox/issues/462

2020-05-30