使用swagger遇到的问题-启动服务出现空指针异常(Unable to scan documentation context default)

使用swagger遇到的问题-启动服务出现空指针异常(Unable to scan documentation context default)


1、问题描述

  1. 在springboot项目中新增了新的需求后,创建entity、Service、Impl、controller类的文件后,重启服务过程中报错(虽然服务能正常启动,但是报错不美观)
  2. 报错日志如下:
ERROR 6292 --- [main] d.s.w.p.DocumentationPluginsBootstrapper : Unable to scan documentation context default

java.lang.NullPointerException: null
	at springfox.documentation.schema.Example.equals(Example.java:131)
	at java.util.Objects.equals(Objects.java:59)
	at springfox.documentation.service.RequestParameter.equals(RequestParameter.java:132)
	at java.util.HashMap.putVal(HashMap.java:648)
	at java.util.HashMap.put(HashMap.java:612)
	at java.util.HashSet.add(HashSet.java:220)
	at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at springfox.documentation.spring.web.readers.operation.OperationParameterReader.apply(OperationParameterReader.java:93)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.operation(DocumentationPluginsManager.java:144)
	at springfox.documentation.spring.web.readers.operation.ApiOperationReader.read(ApiOperationReader.java:72)
	at springfox.documentation.spring.web.scanners.CachingOperationReader.lambda$new$0(CachingOperationReader.java:43)
	at java.util.HashMap.computeIfAbsent(HashMap.java:1127)
	..................


2、研究并解决问题

  1. 针对此问题,研究发现,引起这个错误的是某个entity类,进一步检查发现这个实体类中成员变量使用的属性权限是public;自己在定义变量时,不小心把成员变量的属性都弄成了public,swagger在获取参数时,不能正确识别成员变量的权限。
  2. 检查最近新建的所有entity中成员变量的权限属性,将public改成private,重新启动,不再报空指针异常错误。
.............
Started MesAdminApplication in 38.913 seconds (JVM running for 39.981)

你可能感兴趣的:(spring,boot,工作记录,swagger2,java,spring,boot,spring)