본문 바로가기

JAVA/Spring Boot

Swagger-UI url 변경

반응형

@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SpringFoxConfig extends WebMvcConfigurationSupport{

    @Bean
    public Docket apiDocket() {

        return new Docket(DocumentationType.SWAGGER_2)
            .useDefaultResponseMessages(false)
            .select()
            .apis(RequestHandlerSelectors.basePackage(CommonConstants.BASE_PACKAGE_NAME))
            .paths(PathSelectors.ant("/api/v1/**"))
            .build()
            .apiInfo(getApiInfo())
            ;
    }

    private ApiInfo getApiInfo() {
        return new ApiInfo(
            "SWAN PROJECT",
            "SWAN API server",
            "1.0",
            null,
            new Contact("swan", null, "swan@naver.com"),
            "Copyright ⓒSwan I All rights reserved",
            "https://www.swan.com",
            Collections.emptyList());
    }

    @Override
    protected void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true);
        registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
        registry.addRedirectViewController("/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
        registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/documentation/**").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"
        );
    }
}
반응형

'JAVA > Spring Boot' 카테고리의 다른 글

애플리케이션 설정  (0) 2022.12.12
스프링 부트 기본설정 및 기본 테스트  (0) 2021.06.04
스프링 부트 기본-#2  (0) 2020.10.15
스프링 부트 기본-#1  (0) 2020.10.15
Spring MyBatis사용 및 설정  (1) 2020.10.13