'How to get Swagger UI in SpringBoot (404 error)
I'm trying to add Swagger UI to my REST Api but I can't find swagger ui path or there is a problem with it. Because when I check the paths where swagger ui must be I see the 404 error and I see
No mapping for GET /swagger-ui/index.html
error like that.
My pom.xml file:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</project>
My swagger ui config class:
@Configuration
@EnableSwagger2
public class SpringFoxConfig extends SpringBootServletInitializer {
@Bean
public Docket swagger() {
return new Docket(SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
My application file:
@EnableWebMvc
@SpringBootApplication
public class FlightticketappApplication {
public static void main(String[] args) {
SpringApplication.run(FlightticketappApplication.class, args);
}
}
Solution 1:[1]
The default URL for the UI would be /swagger-ui.html instead of /swagger-ui/index.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kvothe_the_dev |