Using Spring Boot 2.3.1
.
Here is a snippet from pom
:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-version}</version>
</dependency>
Where swagger version is last for now: 3.0.0
.
Swagger configuration:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket swaggerApiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.any())
.apis(RequestHandlerSelectors.basePackage("com.demo.controller"))
.build()
.apiInfo(apiDetails());
}
private ApiInfo apiDetails() {
return new ApiInfo("Carpark Controller API",
"Carpark Service for managing car parks",
"0.0.1",
"",
new springfox.documentation.service.Contact("Jan",
"www.demo.com",
""),
"API License",
"",
Collections.emptyList());
}
}
No Security configuration is added. No any server-path
or some additional configuration.
When the application is up swagger JSON documentation is available:
http://localhost:8080/v2/api-docs
However, if to navigate to swagger UI:
http://localhost:8080/swagger-ui.html
The result will be:
There was an unexpected error (type=Not Found, status=404).
Tried to downgrade swagger version to 2.9.2
result is the same.
How to solve this issue?
Found solution for Spring Boot 2:
Get read from all other swagger dependencies from pom file. Only add next one:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Swagger configuration could be the same as it was before with @EnableSwagger2
.
Start the application.
Swagger UI page is different now:
http://localhost:8080/swagger-ui/index.html
Finally, it works!
Looking for a solution at the web for this issue found the following comment.
Saw the latest samples for Spring Boot version: BootWebmvcApplication
And build.gradle configuration for it.
Here is a link to other projects sources.