Springboot整合swagger2时启动报错Error starting ApplicationContext. To display the conditions report re-run

今天在使用Springboot整合swagger2时启动报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-13 23:34:42.141 ERROR 72552 --- [           main] o.s.boot.SpringApplication               : Application run failed

 查看运行日志发现报以下错误:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

 通过一段时间排查发现注释掉注解@Enableswagger2后springboot正常启动,由此开始查找原因,查找后发现是导入依赖的问题,导入的依赖为:

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

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

解决方法为:

将这两个依赖更改为:

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-boot-starter</artifactId>
   <version>3.0.0</version>
</dependency>

并在原来加@EnableSwagger2注解的类上加上:

@EnableSwagger2
@EnableWebMvc

这两个注解,发现启动成功

访问的地址变为:http://localhost:8080/swagger-ui/index.html

问题成功解决,如有遇到与本人相同问题的小伙伴可参考。

  • 14
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值