SpringBoot简易整合Swagger2

添加依赖

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


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

posted @ 2022-03-31 18:06  无情歌神  阅读(84)  评论(0)    收藏  举报