springboot集成swagger

在做项目的时候,springboot需要集成swagger,所以今天写下这篇博客,来记录下。

1.引入依赖springfox-boot-starter,注意博主这里是引入的3.0.0版本的

  这个starter里面的已经引入了swaggerfox-swagger2和springfox-swagger-ui这两个包。

<!--swagger集成-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

 2.因为博主这里是使用shiro进行权限控制,所以需要在shiro的配置类ShiroConfig类中对swagger的接口进行排除,也就是设置匿名访问。

//swagger放行
filterChainDefinitionMap.put("/swagger-ui/**", "anon");
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
filterChainDefinitionMap.put("/v3/api-docs", "anon");

 3.在浏览器中进行访问即可

http://localhost:8080/swagger-ui/

这就是访问成功后的样子。

这个挺好用的,不需要配置什么东西,真香ヾ(^∀^)ノ

 

4.注意一点:需要在application.yml中添加下面的信息

  #swagger集成,需进行以下配置,
  #因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

这里博主也推荐一篇写的优秀的博客,如果按我的失败了,可以去看看https://blog.csdn.net/weixin_44183847/article/details/119252171

posted @ 2022-03-03 19:15  程序员hg  阅读(121)  评论(2编辑  收藏  举报