Problem
Some services don’t have an UI and the OpenAPI/ Swagger UI should be used as default UI of the service. As so the root should be redirected directly to the SwaggerUI.
Solution
Just add a WebMvc redirect.
@Configuration public class SwaggerConfig implements WebMvcConfigurer { @Override public void addViewControllers(final ViewControllerRegistry registry) { registry.addRedirectViewController("/", "/swagger-ui.html"); // use setStatusCode(HttpStatus.XYZ) for any custom status code if required, e.g. MOVED_PERMANENTLY registry.addRedirectViewController("/swagger-ui", "/swagger-ui.html"); // any other alias } }
Swagger dependencies
Ensure you check the current version:
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.5.8</version> </dependency> <!-- if spring security is used --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-security</artifactId> <version>1.5.8</version> </dependency>