gpt4 book ai didi

spring - 无法访问spring boot应用程序模板文件夹中的html文件

转载 作者:行者123 更新时间:2023-12-02 15:09:46 25 4
gpt4 key购买 nike

html 文件放置在 spring boot 应用程序的 resources/templates/login.html 目录下(如屏幕截图所示),将其部署在 weblogic 服务器中,当我尝试使用以下 URL 访问 login.html 时,它给出找不到网页消息

http://localhost:7001/demo/login.html

下面是截图

enter image description here

在其中一篇文章中,我找到了下面的代码片段并进行了尝试,但没有成功

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}

我没有弄清楚我犯了什么错误,有人可以帮我解决这个......吗?

最佳答案

默认情况下,Spring Boot 提供在 /static/public/resources/META-INF/下找到的所有内容资源,参见docs .因此,您的 static 文件夹中的所有内容都应该得到很好的服务(检​​查)。但是 templates 文件夹不是 static 的子文件夹,所以它不会被提供。如果我没看错,templates 不应该是 URL 路径的一部分,对吧?因此,您可以将 login.html 移动到 static 文件夹,或者可以将 templates 文件夹添加到类路径资源位置。以编程方式(就像您对其他位置所做的那样),或通过设置相应的属性:

spring.resources.static-locations=classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

关于spring - 无法访问spring boot应用程序模板文件夹中的html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44785714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com