SpringBoot简易整合Swagger2


目录
  • 添加依赖
  • springboot中开启swagger
  • 配置文件
  • 访问swagger

添加依赖

        
            io.springfox
            springfox-swagger-ui
            2.9.2
        
        
            io.springfox
            springfox-swagger2
            2.9.2
        


springboot中开启swagger

在启动类上添加注解@EnableSwagger2

@EnableSwagger2
@SpringBootApplication()
public class TestServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(TestServiceApplication.class, args);
    }
}	

如果不在启动类上添加注解打开swagger页面时会提示Unable to infer base url错误


配置文件

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

访问swagger

默认地址为:127.0.0.1:8080/xxx-service/swagger-ui.html