英文:
Would this be a correct to remove Router/Handler Function in the code (Spring Boot)?
问题
在GitHub上有一个名为Spring Boot Cloud的仓库,其中包含一个简单的路由处理程序示例。
@Bean
public RouterFunction<ServerResponse> indexRouter(
@Value("classpath:/static/index.html") final Resource indexHtml) {
// 在根目录下提供静态的 index.html,以方便发布消息。
return route(
GET("/"),
request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml));
}
请注意,index.html位于一个静态文件夹中,这是由Spring在默认模式下实例化的,因此当访问索引路径("/")时会加载此文件。
我理解有些 Web 服务器可能不会将主路径与 index.html 文件关联起来。但是从 Spring Boot 和 Java 的角度来看,如果在这种情况下(当请求主路径时)不将这样的 Bean 包含到项目中,是否正确?
英文:
There is Spring Boot Cloud repository on GitHub with simple route handler example.
@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));
}
You can pay attention that index.html is in a static folder which was instantiated by Spring in default mode, so this file is loaded when index path ("/") is requested.
I understand that it is possible that some webservers will not associate main path with index.html file. However from Spring Boot and Java perspective would this be a correct not to include such Bean to the project in this case (when the main path is requested)?
答案1
得分: 0
我已经尝试在不同的上下文中进行测试,包括Spring Boot安全性,一切都运行正常。因此,我关闭这个问题,但如果有人有更广泛的经验,希望能够提供额外的论据。
英文:
I have tried to test it in different contexts including Spring Boot Security and everything works well. So I close this question, however if someone has wider experience appreciate additional arguments.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论