1

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);
}
mikepoole72
  • 65
  • 1
  • 7
  • This is sometimes weird, you could be trying every possible solution online. Keep changing or downgrading the version of the swagger dependency until it is fixed. This suggestion is not ideal but works for me all the time. – Young Emil Apr 15 '22 at 15:46

1 Answers1

0

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/
Parth Manaktala
  • 884
  • 8
  • 23
  • I did try and add that but I think it is already pulled in from this dependency that I have added. It didn't resolve the issue. My application root is directly off localhost btw, io.springfox springfox-boot-starter 3.0.0 – mikepoole72 Mar 15 '22 at 13:59
  • @mikepoole72 Did any of the answers in this thread help? https://stackoverflow.com/questions/43545540/swagger-ui-no-mapping-found-for-http-request – Parth Manaktala Mar 15 '22 at 14:04