swagger2问题汇总
- 环境:swagger 2.7.0,spring-boot 1.5.9
前言
这里是对在使用swagger时碰到的相关问题汇总。
踩坑
Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
swagger的配置如下:
1 | @Configuration |
详细错误如下:
1 | org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException |
初步诊断,swagger在做scan操作抛出了空指针异常。现在只能google了,发现这事一个bug,并且在2.8.0之后进行了修复(2.8.0修复的问题在这里:https://github.com/springfox/springfox/issues/2186)。
(可参考:https://github.com/springfox/springfox/issues/1876)
这个问题是发生在对controller做了切面后才会出现,If I use AOP advice on my method within @RestController I face this issue too because Spring creates proxy class to wrap controller’s method call。
解决方案
- swagger 2.7.0,spring-boot 1.5.1
既然是个bug,就应该有临时解决方案吧。这还真让我找到了,具体解决的源url就找不到了,就直接帖代码了。
1 | @Configuration |
参考
- https://github.com/springfox/springfox/issues/1876 NullPointerException with Spring Data Rest integration
- https://github.com/springfox/springfox/issues/1860 [spring boot]@EnableAspectJAutoProxy cause endpoint scanning failed