springfox: Getting HTTP 404 error on /swagger-ui.html but other swagger endpoint works
Getting HTTP 404 error on http://localhost:8080/myapp/swagger-ui.html, while integrating swagger-ui in RESTful API app (spring-boot app).
Other swagger endpoints are working as expected (/swagger-resources/configuration/ui, /swagger-resources/configuration/security, /v2/api-docs). I can see the JSON response.
- Versions Info
- spring-boot 1.3.5 (spring-boot-starter-tomcat).
- Swagger 2.5.0 for both springfox-swagger2 & springfox-swagger-ui
- This is a spring-boot app and serves RESTful api’s and does not have any static content. Hence no webapp, web, META-INF/resources etc folders in source code.
- pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency>
- I am not using @EnableWebMvc anywhere in code
- SwaggerConfiguration.java
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfiguration implements EnvironmentAware {
@Bean
public Docket swaggerSpringfoxDocket() {
Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
.genericModelSubstitutes(ResponseEntity.class).forCodeGeneration(true)
.genericModelSubstitutes(ResponseEntity.class)
.directModelSubstitute(LocalDate.class, String.class)
.directModelSubstitute(LocalDateTime.class, Date.class)
.directModelSubstitute(ZonedDateTime.class, Date.class).select()
.paths(regex("/api/.*")).build();
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfo(propertyResolver.getProperty("title"),
propertyResolver.getProperty("description"),
propertyResolver.getProperty("version"),
propertyResolver.getProperty("termsOfServiceUrl"),
new Contact(propertyResolver.getProperty("contact.name"),
propertyResolver.getProperty("contact.url"),
propertyResolver.getProperty("contact.email")),
propertyResolver.getProperty("license"),
propertyResolver.getProperty("licenseUrl"));
}
- Not sure if this will impact, but i do have below for configuring Metrics
@Configuration
public class WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer {
@Autowired(required = false)
private MetricRegistry metricRegistry;
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 31 (8 by maintainers)
I also received 404 on getting HTML UI docs. I am having spring boot webflux project and the resolution was fairly simple: current 3.0.0-SNAPSHOT version changed the UI URL to /swagger-ui/ instead of the old /swagger-ui.html
Remove all you explicit tweaks and hacks and just depend on the new springfox-boot-starter as written here.
I realize this is closed, but for people with similar problems the issue I had was we had a class extending the WebMvcConfigurationSupport and overriding methods, but we should have been using WebMvcConfigurerAdapter and overriding methods there. That fixed our issues.
Hi, Also I was facing this problem, I found
@EnableWebMvc
annotation If I use this annotation Swagger UI will not work then I removed that now It’s workingWith all due respect, if you are going to respond you might as well highlight the how as well as the what. Otherwise, you’ll just continue to receive questions from ignorant folks such as myself. Last time I checked, when telling my libraries/microservices/api’s what to do, they tend not to react. I know it can be exhausting so thank you anyway.
I was able to find a temporary solution by adding the following function within the main application class of the project. I tried creating a separate configuration class and trying to implement the same functionality with a non-deprecated class, but I’ve been unsuccessful so far. (I snagged this solution from a different comment thread which I cannot find now)
I have encountered this problem before and the problem was in the below line in application.properties spring.resources.add-mappings=false
remove it or change it’s value to true
Found the root cause in my case. Was stupid mistake.
application.yml (app config) has below preventing other static mappings to be resolved.
Removed the same from application configuration and swagger-ui.html came up.
Faced the same problem and the official migration recommendations have helped me.
@dilipkrish - I have tried all the above solutions and i am still facing this issue. But still getting “No mapping found for HTTP request with URI [/swagger-ui.html] in DispatcherServlet with name ‘dispatcherServlet’” error. I am running Spring boot 2.0.2.RELEASE with Swagger 2.8.0 version. I have added below manual mappings for Swagger-ui.html also. See the below code -
@jjathman thanks for that tip! Yes If I remember right, when you implement
WebMvcConfigurationSupport
, spring boot assumes you’re in charge of all the configuration and will disable auto configuration.For me worked http://localhost:9090/swagger-ui/index.html, together with the migration guide. 😃 Found at https://github.com/springfox/springfox/issues/3345
@txiasummer unfortunately that is true, I think spring boot 2.2 is significantly different that 3.0.0 had to make some implicit breaking changes. However until that time 2.9.2 is your best friend
Hello! I had the same issue today. For me the problem was using springfox-swagger2:3.0.0 and springfox-swagger2-ui:3.0.0 but my spring boot is at 2.0.6.RELEASE. I cannot upgrade Spring Boot due to some dynamoDB depencies holding me back. Anyway, I kept getting the 404 when i went to /swagger-ui.html. I tried everything people suggested before and nothing worked. So in the end, I downgraded to swagger 2.9.2 and that worked for me. Hope this helps someone else! 😃
@Vladis466 I plan to create a demo project with spring security and how its done. For one, most of these problems/solutions are one-offs and documentation is already available, its just a matter of looking.
swagger启动后,老是报错下面的url无法打开swagger-ui.html, 提示内部url无法打开swagger-resources/configuration/ui
原因是: 启用了组件扫描导致:@ComponentScan(basePackages = {“com.haizhi.dao”,“com.haizhi.controll”,“com.haizhi.service”}) 这个问题真是费解。
解决办法:注释掉扫描注解即可: //@componentscan(basePackages = {“com.haizhi.dao”,“com.haizhi.controll”,“com.haizhi.service”})
Just guessing it seems like spring boot isn’t picking up the resources automatically. You may have to manually set up the resources.