问题一:完成Swagger配置,但是页面打开不了。
原因:被项目中的拦截器给拦截了。
解决方法:
public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册拦截器
InterceptorRegistration registration = registry.addInterceptor(new AdminInterceptor());
//定义排除swagger访问的路径配置
String[] swaggerExcludes=new String[]{"/swagger-ui.html", "/swagger-resources/**", "/webjars/**"};
registration.addPathPatterns("/**") //所有路径都被拦截
registration.excludePathPatterns(swaggerExcludes); //添加不拦截路径
WebMvcConfigurer.super.addInterceptors(registry);
}
}
问题二:启动报错:
原因:Springboot 版本与 Swagger 版本不匹配
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-22 15:25:39.767 ERROR 21576 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecyclePr