更改Spring-boot静态Web资源位置?

Tua*_*uan 5 model-view-controller thymeleaf spring-boot

基于本教程:

http://spring.io/guides/gs/serving-web-content/

我可以使用百里香为这个地方的景观服务

/src/main/resources/templates/
Run Code Online (Sandbox Code Playgroud)

但是,我必须将静态Web内容(css,js)放在另一个位置:

/src/main/webapp/resources
Run Code Online (Sandbox Code Playgroud)

并链接hello.html中的资源:

<link href="resources/hello.css" />
<script src="resources/hello.js"></script>
Run Code Online (Sandbox Code Playgroud)

目录结构是:

??? src
    ??? main
        ??? java
            ??? hello.java
        ???resources
            ???templates
               ???hello.html
        ???webapp
            ???resources
               ???hello.js
               ???hello.css
Run Code Online (Sandbox Code Playgroud)

问题是当我运行Web服务器时,静态文件的链接是有效的.但是如果我在离线模式下打开html文件,链接就会被破坏.

我可以移动静态资源吗?

/src/main/webapp/resources
Run Code Online (Sandbox Code Playgroud)

至:

/src/main/resources/templates/resources
Run Code Online (Sandbox Code Playgroud)

新的目录结构如下:

??? src
    ??? main
        ??? java
            ??? hello.java
        ???resources
            ???templates
               ???hello.html
               ???resources
                  ???hello.js
                  ???hello.css
Run Code Online (Sandbox Code Playgroud)

我试了但是不行.

Dav*_*yer 12

尝试src/main/resources/static(或src/main/resources/publicsrc/main/resources/resources).所有这些都是由Spring Boot autoconfig注册的.