【问题标题】:Spring Boot: How to change the path to serve static files?Spring Boot:如何更改提供静态文件的路径?
【发布时间】:2018-11-25 17:38:49
【问题描述】:

我有一个 Spring Boot 项目位于路径“C:\Personal Projects\Spring”中,我希望它服务于名为 index.html 的浏览器静态 HTML 文件,该文件位于“C:\Personal Projects\Game\构建”。

因此,我写了如下代码:

@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 错误。

你知道我做错了什么吗?

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    应该是:

    properties.setProperty("spring.resources.static-locations",
                    "file:C:\\Personal Projects\\Game\\build");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2017-07-12
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 2020-01-20
      相关资源
      最近更新 更多