解决swagger主页访问,返回报错500问题
作者:郝猿
swagger主页访问,返回报错500
报错日志
下面展示一些 内联代码片。
java.lang.NullPointerException: null
at springfox.documentation.swagger2.mappers.RequestParameterMapper.bodyParameter(RequestParameterMapper.java:264)
at springfox.documentation.swagger2.mappers.RequestParameterMapper.mapParameter(RequestParameterMapper.java:149)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper.beforeMappingOperations(ServiceModelToSwagger2Mapper.java:125)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2MapperImpl.mapOperation(ServiceModelToSwagger2MapperImpl.java:109)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper.mapOperations(ServiceModelToSwagger2Mapper.java:270)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper.lambda$mapApiListings$2(ServiceModelToSwagger2Mapper.java:258)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
at java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:2897)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:423)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper.mapApiListings(ServiceModelToSwagger2Mapper.java:253)
at springfox.documentation.swagger2.mappers.ServiceModelToSwagger2MapperImpl.mapDocumentation(ServiceModelToSwagger2MapperImpl.java:48)
at springfox.documentation.swagger2.web.Swagger2ControllerWebMvc.getDocumentation(Swagger2ControllerWebMvc.j
这个问题找起来,需要慢慢debug
在(RequestParameterMapper.java:264)的地方打断点
找到报错的swagger注解类,基本上都是注解使用错误
我这问题是入参是两个参数
注解缺注明了三个参数,导致swagger报空指针
删除第三个swagger 入参注解就ok了
由于swagger报错不会提示具体是哪个类的注解有错误
所以需要慢慢的debug 循环
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。