I am trying to integrate Spring Boot 2.0 with swagger but not showing up end points.When I looked to developer console on network tab ,it says that I couldn't find "http://localhost:8080/swagger-resources/configuration/ui" and return 404.
-
which swagger implementation you are using ? .. Try to hit url as localhost:8080/swagger-ui.html– abhi3232Mar 31, 2018 at 10:21
-
Please add more info: do you use springfox, do you have an existing controllers or will using codegen, do you have a Oauth or another security configured with your SpringBoot?– Georgi StoyanovApr 3, 2018 at 20:24
-
If you can also post what your application.properties looks like. I ran into the same issue where all my configurations and swagger documentation end points are working until I specify spring.resources.static-locations[0]=file:src/main/resources/static/ and spring.resources.static-locations[1]=classpath:/static/– olyjoshJun 4, 2018 at 10:37
2 Answers
We solved this problem by adding resource handler for swagger:
Example:
@Configuration
public class MvcConfiguration extends WebMvcConfigurationSupport {
@Value("${spring.application.name}")
private String applicationName;
//...irrelevant code here
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
If you have @EnableWebMvc or @WebMvcConfigurationSupport annotation anywhere in the project then remove these or add custom resource handlers to configure swagger-ui.
Here's some common solutions: https://github.com/springfox/springfox/issues/2396#issuecomment-402150402