Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将swagger-ui.html作为默认上下文路径_Java_Spring_Spring Boot_Swagger 2.0 - Fatal编程技术网

Java 如何将swagger-ui.html作为默认上下文路径

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

我有一个默认上下文路径为“/”的应用程序,但我想将默认上下文路径设置为swagger-ui.html

假设我的应用程序在8080上运行,当我放置localhost:8080时,应用程序应该重新指向localhost:8080/swagger ui.html

我在application.properties中添加了以下内容

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”)中提到的解决方法;但是没用不,我没有