打开swagger文档报空指针异常
java.lang.NullPointerException: nullat springfox.documentation.oas.mappers.SchemaMapper.model(SchemaMapper.java:97)at springfox.documentation.oas.mappers.SchemaMapper.mapModel(SchemaMapper.java:85)at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapperImpl.fromRepresentation(ServiceModelToOpenApiMapperImpl.java:187)at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.map(ServiceModelToOpenApiMapper.java:216)at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapperImpl.mapOperation(ServiceModelToOpenApiMapperImpl.java:113)at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.mapOperations(ServiceModelToOpenApiMapper.java:283)at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.lambda$mapPaths$4(ServiceModelToOpenApiMapper.java:264)at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
使用排除法,定位到是某个新加的controller方法引起的,逐渐尝试,发现是方法的返回值为void引起的,只要返回值不是void,就能正常打开,服了,还是准备换spring doc吧(哭笑)
问了ai,大概是这个原因:
-
Springfox Bug:某些版本(尤其是
3.0.0
)的springfox-oas
模块在解析Void
类型时仍然会触发NullPointerException
,因为内部SchemaMapper
没有正确处理Void
类型的模型映射。 -
OAS 3.0 兼容性问题:Springfox 对 OpenAPI 3.0 的支持不够完善,
void
/Void
方法在某些情况下无法正确生成 Schema。