'Can't get swagger2 to display swagger-ui.html

The problem

Am learning java spring boot and my problem is getting the swagger front-end to load from http://localhost:8080/swagger-ui.html#/ I get the console message as follows:

WARN 23432 --- [nio-8080-exec-9] o.s.web.servlet.PageNotFound : No mapping for GET /swagger-ui.html

Background

I've built out a starter project using spring boot with a basic API and have tested the endpoints with postman ok. I'm using v2.6.4 of spring-boot-starter-parent.

I'm trying out swagger for the first time and have included the following in my pom.xml

groupId io.springfox artifactId springfox-boot-starter version 3.0.0

In my application.yml I have added the following to resolve a build issue which was related to a version/dependency mismatch.

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  
  

I've added the following class to my config package based on a tutorial I am following.

@Configuration
@EnableWebMvc
@Import(SpringDataRestConfiguration.class)
public class ApplicationSwaggerConfig {

    @Bean
    public Docket speakersApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

I found some articles saying to override resource handling as follows to cure the problem but it is not helping:

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

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


Solution 1:[1]

In order to enable swagger ui using spring-fox, you need to add an additional dependency in your pom.

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

(This is the latest version, you can use any version based on the usecase)

The path of the swagger UI will be at the below link or using swagger-ui.html page.

http://localhost:8080/your-app-root/swagger-ui/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Parth Manaktala