error code 404 on /swagger-ui.html, non spring boot app

See original GitHub issue

Application is a non-boot app, I’ve tried almost all the possible solutions present on here but none of them seemed to work,

spring-boot-version: 2.1.6.RELEASE spring-webmvc : 5.1.8.RELEASE springfox-swagger2 : 2.9.2 springfox-swagger-ui : 2.9.2

the server starts but when I try /swagger-ui.html or api-docs it returns a 404. Other api(s) are working perfectly fine.

`@EnableWebMvc @EnableSwagger2 @Configuration public class SwaggerConfig extends WebMvcConfigurerAdapter {

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

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

	super.addResourceHandlers(registry);
}

} `

let me know if you need anything else. Please help

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
dilipkrishcommented, Jul 13, 2020

This should be fixed in 3.0.0. the new url in 3.0.0 is /swagger-ui/index.html or /swagger-ui/ rather than /swagger-ui.html

2reactions
kvndkmcommented, Aug 2, 2021

Hello, I am seeing the same error 404 on swagger end point. My application non-spring boot app (Using Spring 5.3.6 web application).

I am able to access /v2/api-docs but when I try /swagger-ui/ or /swagger-ui/index.html, I am seeing 404 not found error. Your suggestion on what I am doing wrong here, is much appreciated

POM <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>3.0.0</version> </dependency> Spring services XML

<bean id="saSwaggerConfig"
      class="com.silverrailtech.ui.configuration.SASwaggerConfig">
</bean>

Swagger Config class @EnableSwagger2 public class SASwaggerConfig implements WebMvcConfigurer {

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

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/swagger-ui/")
            .setViewName("forward:" + "/swagger-ui/index.html");
}

}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger with Spring Boot 2.0 leads to 404 error page
I was able to make it work with Spring boot version 2.0.4.RELEASE and this blog post: I added these dependencies:
Read more >
Receiving 404 error on Swagger UI with Spring-Springboot
I had a similar problem where /swagger-ui.html (or the new endpoint version /swagger-ui/) returned 404, but the /v2/api-docs returned a valid json.
Read more >
OpenApi 3 (Swagger UI), Spring Boot, Spring Security - Medium
antMatchers() rule to your SecurityConfig still has 404 error. I'm using: Spring Boot v2.4.1; Spring Security; OpenApi 3 with swagger-ui ...
Read more >
Documenting a Spring REST API Using OpenAPI 3.0 - Baeldung
Learn how to generate OpenAPI 3.0 specifications for a Spring REST ... can generate a Spring Boot REST client using Swagger Code generator....
Read more >
Springfox Reference Documentation - GitHub Pages
For non-boot applications springfox-swagger-ui is no longer ... In this example we override the 500 error code for all GET requests …​.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found