启动报错
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
这个呢是因为springboot2.6更改了请求路径与与SpringMVC路径匹配规则,已经不是原来的AntPathMatcher
了,改为了PathPatternParser
。可能swagger3.0的一些地址还没作出相应的更新所以出错了。
解决的方法呢就是:
yml
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
现在我们终于是解决了springboot整合swagger后报错的问题了,但是来到了下一个问题springboot启动是启动了但是呢我们却访问不了。
依赖不够
对于依赖呢swagger3.0需要3个依赖而swagger2.0只需要两个依赖。
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
在我们使用swagger的过程中这些依赖是必须的
我们用的时候是使用java配置swagger所以
这两个注解是必须的
@Configuration @EnableOpenApi
现在我们能来尝试启动swagger然后打开页面文档了
如果你按照我的步骤来的话应该是这样的完全启动了这个教程非常新你也不用怕教程太老版本不匹配的问题
访问swagger文档
还有一件事
swagger3.0访问后台地址:http://localhost:8080/swagger-ui/index.html
访问地址跟2.0的不一样了请用这个地址
好了中遇到了我们的启动环节了
如果没有错的话你应该啊能看到这个页面,那么恭喜你已经成功的整合了swagger