代码之家  ›  专栏  ›  技术社区  ›  CrazySynthax

spring boot:如何更改路径以提供静态文件?

  •  0
  • CrazySynthax  · 技术社区  · 6 年前

    我有一个spring boot项目,位于路径“c:\ personal projects\spring”中,我希望它能用于浏览器名为index.html的静态html文件,该文件位于“c:\ personal projects\game\build”中。

    因此,我编写了以下代码:

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

    你知道我做错了什么吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   CrazySynthax    6 年前

    应该是:

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