第一次使用Swagger时报NullPointerException
在pom文件中引入Swagger
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.1.RELEASE</version>
</dependency>
在启动项中加入注解

@EnableSwagger2Doc 添加注解
接口注解

@ApiOperation(value = "查询终端状态")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = JhLog.class) })
运行出现NullPointerException

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决运行空指针问题

将pom中的SpringBoot版本降低到2.6.0以下

再次运行问题解决


本文介绍了解决在Spring Boot项目中使用Swagger时遇到的NullPointerException问题的方法。通过调整pom文件中的依赖版本,成功解决了启动时出现的应用上下文异常。
1535





