SpringBoot2.7整合Swagger3.0报错

2023-06-02后端1 分钟112 次阅读
AI 摘要鱼粮不足,AI 今天先歇着 · 正文在下面

问题

今天把某个项目的SpringBoot和Swagger做了升级,启动报了:Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
image.png

解决

经过查阅资料,发现springboot2.6之后更改了请求路径与与SpringMVC路径匹配规则,已经不是原来的AntPathMatcher了,改为了PathPatternParser。可能Swagger3.0还没有做兼容吧,不过也挺久了。。
image.png
如果你是application.properties,加这个参数

properties 复制代码
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

如果你是application.yml,加这个参数

yml 复制代码
spring:
  mvc:
    pathmatch:
        matching-strategy: ant_path_matcher

补充

1 swagger3.0访问地址:http://localhost:8888/swagger-ui/index.html
2. swagger3.0要将@EnableSwagger2注解改为@EnableOpenApi

觉得有用就点个赞,不用登录也能读

评论

0 条
登录 之后才能评论
—
还没有评论,来说第一句