本章导学:
- <dependency>
- <groupId>io.springfoxgroupId>
- <artifactId>springfox-boot-starterartifactId>
- <version>3.0.0version>
- dependency>
@EnalbeOpenApi
注意:swaager3.0改了默认访问路径
我们需要访问:localhost:端口号/swagger-ui/index.html
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/swagger-ui/**")
- .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
- }
如果有配置拦截器,我们还需要放行
- @Override
- protected void addInterceptors(InterceptorRegistry registry) {
- //拦截器B不拦截以下路径
- registry.addInterceptor(loginInterceptor).excludePathPatterns(
- "/user/code",
- "/user/login",
- "/shop/**",
- "/shop-type/**",
- "/blog/hot",
- "/upload/**",
- "/voucher/**",
- "/swagger**/**",
- "/webjars/**",
- "/v3/**",
- "/doc.html"
- )
- .addPathPatterns("/**").order(10);
-
- //拦截器A拦截所有路径
- registry.addInterceptor(reloadTokenInterceptor).addPathPatterns("/**")
- .excludePathPatterns(
- "/swagger**/**",
- "/webjars/**",
- "/v3/**",
- "/doc.html"
- ).order(5);
-
- }
测试一下: