Reputation: 372
I have an application which with default context path as "/" but I want to make default context path as swagger-ui.html.
suppose if my application runs on 8080 , when I put localhost:8080 , application should re-direct to localhost:8080/swagger-ui.html
I had put following in application.properties
server.servlet.context-path=/swagger-ui.html
but it is not working, could some one help me
Below are swagger dependencies I am using
compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox:springfox-swagger-ui:2.9.2'
Upvotes: 0
Views: 1789
Reputation: 194
You can redirect initial path "/" in controller like this:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("redirect:" + "/swagger-ui.html");
}
or you can extend 'WebMvcConfigurerAdapter' class in main class and override method 'addViewControllers' like this:
@SpringBootApplication
public class Application extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers (ViewControllerRegistry registry) {
registry.addRedirectViewController("/", "/swagger-ui.html");
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Upvotes: 1