按照以下配置即可修复
- Swagger配置类
@Configuration public class SwaggerConfig implements WebMvcConfigurer { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.humorchen.springboot_test.controller")).paths(PathSelectors.any()).build(); } private ApiInfo getApiInfo() { return new ApiInfoBuilder().title("SprintBoot学习测试接口文档").description("描述信息:author:humorchen").contact("联系信息:qq3301633914").version("1.0").build(); } }
拦截器配置类
@Configuration public class InterceptorRegister implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new NeedLoginInterceptor()) .addPathPatterns("/springboot_test/user/**") .excludePathPatterns("/login") .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**"); } }