Springboot 引入 Swagger 遇到的问题

问题一:完成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
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值