Reputation: 141
I am trying to add swagger ui documentation to my spring boot application. Here the steps I did into my code:
Add dependencies to my POM.XML
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
then add swagger annotation to the swagger config as follow:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.foo.samples.swaggersample"))
.paths(PathSelectors.any())
.build();
}
}
when executing this url: http://localhost:8080/my-app-name/swagger-ui.html I got this result:
Your help will be more than welcome!
Upvotes: 0
Views: 1212
Reputation: 152
I had this similar issue (my error code is 404 not 500 like yours), until I added resource handler:
@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/");
}
Hope that helps
Upvotes: 1