gpt4 book ai didi

java - Spring Boot 不会自动提供静态文件

转载 作者:行者123 更新时间:2023-12-01 09:49:23 25 4
gpt4 key购买 nike

我有 SpringBoot 1.3.3 和一个在端口 8080 上公开的工作 Java API。但是,除了这个 API,我还想公开一个直接位于 {projectName}/src/main/resources/下的 index.html 文件,根据到 Springboot 文档,这应该会自动提供,但是当我导航到 http://localhost:8080/index.html 时我得到了 404。我没有在任何地方使用 @EnableWebMVC,并尝试添加我自己的配置文件,如下所示,但是没有任何效果,所以我有点不知所措。任何帮助将不胜感激!

@Configuration
@EnableWebMvc
@ComponentScan
public class ServerConfiguration extends WebMvcAutoConfiguration {

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

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

最佳答案

将文件放入/src/main/resources/public/

关于java - Spring Boot 不会自动提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37707494/

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