SpringBoot 的那些不贴了就直接放Swagger配置 样本配置 如下
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
新版本不需要在启动项配置 @EnableSwagger2但是需要注意,如果启动抛出如下图异常
Failed to start bean 'documentationPluginsBootstrapper';
nested exception is java.lang.NullPointerException
需要在启动项配置 @EnableWebMvc(下面是参考别人的)
因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher。该注解可以更改匹配规则。也可以直接修改配置spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER来更改规则。或者降低SpringBoot 到 2.5 以下版本
如果还需要自定义配置的方式,请查阅其他文案。
访问地址是根据你项目端口定的: 默认端口如果没有配置就是8080.如果有配置就是对应端口
【这里直接贴解决问题,不分析原因。喜欢卷的朋友可以去看源码】
http://localhost:8080/swagger-ui/index.html
(低于 3.0版本 为http://localhost:8081/swagger-ui.html 【端口有误请查证,就不去验证低版本了】 )
具体地址还得看项目 http://ip:项目端口/swagger-ui/index.html (请以最后这个为准)
版权声明:本文为qq_28061501原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。