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);
}