Java 如何将swagger-ui.html作为默认上下文路径
我有一个默认上下文路径为“/”的应用程序,但我想将默认上下文路径设置为swagger-ui.html 假设我的应用程序在8080上运行,当我放置localhost:8080时,应用程序应该重新指向localhost:8080/swagger ui.html 我在application.properties中添加了以下内容Java 如何将swagger-ui.html作为默认上下文路径,java,spring,spring-boot,swagger-2.0,Java,Spring,Spring Boot,Swagger 2.0,我有一个默认上下文路径为“/”的应用程序,但我想将默认上下文路径设置为swagger-ui.html 假设我的应用程序在8080上运行,当我放置localhost:8080时,应用程序应该重新指向localhost:8080/swagger ui.html 我在application.properties中添加了以下内容 server.servlet.context-path=/swagger-ui.html 但它不起作用,有人能帮我吗 下面是我正在使用的招摇过市依赖项 compile 'io
server.servlet.context-path=/swagger-ui.html
但它不起作用,有人能帮我吗
下面是我正在使用的招摇过市依赖项
compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox:springfox-swagger-ui:2.9.2'
您可以在控制器中重定向初始路径“/”,如下所示:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("redirect:" + "/swagger-ui.html");
}
@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);
}
}
或者,您可以在主类中扩展“WebMVCConfigureAdapter”类,并重写方法“AddViewController”,如下所示:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("redirect:" + "/swagger-ui.html");
}
@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);
}
}
我认为这是不可配置的。但是您可以尝试我尝试过的registry.addRedirectViewController(“/”,“/swagger ui.html”)中提到的解决方法;但是没用不,我没有