0

I have the following library referenced in my POM file

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.14</version>
    </dependency>

In my code I have the following class defined

@EnableWebMvc
public class SwaggerMVC implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
            .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

I also have this class defined

@Configuration
public class SwaggerConfig {

   @Bean
   public GroupedOpenApi api() {
      return GroupedOpenApi.builder()
            .group("my-api")
            .pathsToMatch("/**")
            .pathsToExclude("/error.*")
            .pathsToExclude("/actuator.*")
            .pathsToExclude("/test.*")
            .pathsToExclude("/swagger-ui.html")
            .pathsToExclude("/swagger-ui/**")
            .pathsToExclude("/v3/api-docs/**")
            .pathsToExclude("/v3/api-docs.yaml")
            .pathsToExclude("/api-docs/**")
            .pathsToExclude("/api-docs.yaml")
            .pathsToExclude("/swagger-ui-custom.html")
            .pathsToExclude("/cloudfoundryapplication.*")
            .build();
    }
}

While experimenting with this and trying to get it to work, I added this to my application.properties file

springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui-custom.html

But, no matter what I try, I always get a 404 when I hit any of the following urls

http://localhost:8080/api-docs
http://localhost:8080/v3/api-docs
http://localhost:8080/api-docs.yaml
http://localhost:8080/v3/api-docs.yaml
http://localhost:8080/swagger-ui.html

What am I doing wrong?

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • 1
    check springdoc documentation here https://springdoc.org/#getting-started no need for any extra configuration. just add the dependency to your pom.xml and go to `http://server:port/context-path/swagger-ui.html` if it doesn't work, check your spring-security configuration and allow swagger path. – Rayen Rejeb Feb 21 '23 at 15:02

0 Answers0