Spring Boot Web Redirect
November 1, 2019
When using Swagger with Spring Boot, the UI is provided at /swagger-ui.html
. In order to show this from the root URL, I needed to add a web controller to my project, which will redirect from / to the ui page.
This can be done with the following class:
package com.drumcoder.diary.web.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class RootController { @GetMapping("/") public String greeting() { return "redirect:/swagger-ui.html"; } }