Added Springfox Swagger-UI and it's not working, what am I missing?
io.springfox >= 2.X |
io.springfox >= 3.X |
---|---|
|
|
browser URL http://localhost:8080/swagger-ui.html |
browser URL http://localhost:8080/swagger-ui/ http://localhost:8080/swagger-ui/index.html |
Must Need
|
Must Need
|
|
|
I tried most of these answers and the final solution was creeping..
The right URL is the following
http://localhost:8080/swagger-ui/
I'm using Springfox swagger-ui 3.x.x
Refer for complete swagger setup: http://muralitechblog.com/swagger-rest-api-dcoumentation-for-spring-boot/
Already a lot of answers have stated the right answer but still, there has been some confusion regarding the error.
If you are using Spring Boot Version >= 2.2, it is recommended to use SpringFox Swagger version 3.0.0
Now, only a single dependency is required to be added in the pom.xml.
<!-- Swagger dependency -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Once the application is started, you can get the documentation by hitting either of the new swagger URLs.
Option 1: http://localhost:8080/swagger-ui/
Option 2: http://localhost:8080/swagger-ui/index.html
I ran into this issue because I had endpoints with request mappings that had path variables of this form: /{var}. Turns out that this is an issue for both GET and POST endpoints i.e. GET /{var} and POST /{var} block swagger-ui. Once I made the paths more specific, I got swagger-ui to work.
Quote from https://github.com/springfox/springfox/issues/1672
When spring finds a simple path with just one variable swagger cannot intercept the URLs.
Found by investigating various ideas in comments.
For Spring Version >= 2.2, you should add the dependency springfox-boot-starter
pom.xml:
<properties>
<java.version>1.8</java.version>
<io.springfox.version>3.0.0</io.springfox.version>
</properties>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${io.springfox.version}</version>
</dependency>
</dependencies>
ApplicationSwaggerConfig
@Configuration
@EnableSwagger2
public class ApplicationSwaggerConfig {
@Bean
public Docket employeeApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Swagger-UI link: http://localhost:8080/swagger-ui/index.html#/