首页 > 解决方案 > Spring Boot 更改 URL 并破坏静态资产

问题描述

我有我试图在 url 下呈现的静态资产localhost:8080/test

我的目标是点击localhost:8080/test并让它index.html在资源目录中呈现页面。目前,当我这样做时,它会将 url 重定向到localhost:8080并加载内容,然后当我刷新页面时,它会破坏“whitepage error”。我应该如何在这条路径下正确地为我的 /test url 提供静态资产?

控制器

  @Controller
  class Welcome {
    @RequestMapping("/test")
    public String greeting() {
      return "index.html";
    }
    registry
        .addResourceHandler("/**")
        .addResourceLocations("classpath:/static/templates/")
        .setCachePeriod(3000);
  }

在此处输入图像描述

标签: javaspring-boot

解决方案


推荐阅读