Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.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 删除代码中的路由器/处理器功能(Spring Boot)是否正确?_Java_Spring Boot - Fatal编程技术网

Java 删除代码中的路由器/处理器功能(Spring Boot)是否正确?

Java 删除代码中的路由器/处理器功能(Spring Boot)是否正确?,java,spring-boot,Java,Spring Boot,GitHub上有Spring引导云,带有简单的路由处理程序 @Bean 公共路由器功能索引路由器( @值(“classpath:/static/index.html”)最终资源索引{ //在根目录下提供static index.html,以方便消息发布。 回程( 获取(“/”), 请求->确定().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml)); } 您可以注意index.html位于一个静态文件夹中,该文件夹是Spring在默认模

GitHub上有Spring引导云,带有简单的路由处理程序

@Bean
公共路由器功能索引路由器(
@值(“classpath:/static/index.html”)最终资源索引{
//在根目录下提供static index.html,以方便消息发布。
回程(
获取(“/”),
请求->确定().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml));
}
您可以注意index.html位于一个静态文件夹中,该文件夹是Spring在默认模式下实例化的,因此在请求索引路径(“/”)时加载此文件


我知道有些Web服务器可能不会将主路径与index.html文件关联。然而,从Spring Boot和Java的角度来看,在这种情况下(当请求主路径时),不将这样的Bean包含到项目中是正确的吗?

我尝试在不同的上下文中测试它,包括Spring Boot安全性,并且一切都很好。所以我结束这个问题,但是如果有人有更广泛的经验,我会欣赏更多的论点

@Bean
public RouterFunction<ServerResponse> indexRouter(
        @Value("classpath:/static/index.html") final Resource indexHtml) {

    // Serve static index.html at root, for convenient message publishing.
    return route(
            GET("/"),
            request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml));
}