spring-boot - Spring Boot:如何更改提供静态文件的路径?
问题描述
我有一个位于路径“C:\Personal Projects\Spring”中的 Spring Boot 项目,我希望它为位于“C:\Personal Projects\Game\build”中的名为 index.html 的浏览器静态 HTML 文件提供服务。
因此,我编写了以下代码:
@SpringBootApplication
@EnableAutoConfiguration
public class Main {
public static void main(String[] args) throws IOException {
SpringApplication app = new SpringApplication(Main.class);
Properties properties = new Properties();
properties.setProperty("spring.resources.static-locations",
"C:\\Personal Projects\\Game\\build");
app.setDefaultProperties(properties);
app.run(args);
}
}
当我运行程序并打开“localhost:8080/index.html”浏览器时,我收到 404 错误。
你知道我做错了什么吗?
解决方案
它应该是:
properties.setProperty("spring.resources.static-locations",
"file:C:\\Personal Projects\\Game\\build");
推荐阅读
- javascript - Vue.js 中的 Spotify
- reactjs - 如何模拟 React setState 进行 API 测试
- swift - 如何在新根目录下将文本字段添加到 Firebase?
- visual-c++ - 为什么我的 lp 文件为每个变量提供#number?
- python - 过滤以特定字符串开头的 txt 行 (Python)
- java - 转换百分比
- android - 如何在Android中只读取第一个子值
- nativescript - HTMLElement 未定义 - Nativescript-vue
- android - 重复的jar入口-android
- c# - 将参数传递给事件处理程序