引入swagger报错Unable to infer base url. This is common when using dynamic servlet registration or when…

原本我的依赖版本为:

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

config为

package com.jike.blog.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jike.blog.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("博客管理系统")
                .description("Blog management system")
                .termsOfServiceUrl("http://www.xxx.com/")
                .version("1.0")
                .build();
    }

}

生成环境是dev

spring:
  profiles:
    active: dev

但还是报错
Unable to infer base url. This is common when using dynamic servlet registration or when…

后来我调整依赖版本为

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>

又报错:
Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException

好像是springboot和swagger的版本不兼容……

然后我在application.yml处加了一个

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

然后就可以了……

你可能感兴趣的:(java,springboot)