Springboot3.0 +OpenApi

pom.xml

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
WebMvcConfigurer
@Configuration
public  class InterceptorConfig  implements WebMvcConfigurer {

    @Bean
    public  AuthInterceptor authInterceptor(){
        return  new AuthInterceptor();
    }
    @Override
    public  void  addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor(authInterceptor()).excludePathPatterns("/","/account/login","/webjars/**","/swagger-resources/**","/swagger-ui/**","/v3/**")
           .addPathPatterns("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
}

SpringDocConfig

@Configuration
public class SpringDocConfig {

    @Bean
    public OpenAPI restfulOpenApis() {
        return  new OpenAPI()
                .info(new Info().title("Spring Boot 3.0 Restful Open API").description("The Open API").version("1.0").license(new License().name("Apache")))
                .externalDocs(new ExternalDocumentation()
                        .description("The Open API"));
    }
}

 

posted @ 2023-01-11 14:53  在 水 一 方  阅读(1199)  评论(0编辑  收藏  举报