Spring Boot app not serving static content

后端 未结 2 530
悲&欢浪女
悲&欢浪女 2020-12-31 17:07

I am using Spring Boot, and am trying to make my static resources (CSS, JS, Fonts) available when deployed. The source code is available for you to look at or clone from htt

2条回答
  •  [愿得一人]
    2020-12-31 18:06

    Put static resources under the directory:

    /src/main/resources/static
    

    You can also use public or resources instead of static as folder name.

    Explanation: your build tool (Maven or Gradle) will copy all the content from /src/main/resources/ in the application classpath and, as written in Spring Boot's docs, all the content from a directory called /static (or /public or /resources) in the classpath will be served as static content.


    This directory could works also, but it is discouraged:

    /src/main/webapp/
    

    Do not use the src/main/webapp directory if your application will be packaged as a jar. Although this directory is a common standard, it will only work with war packaging and it will be silently ignored by most build tools if you generate a jar.

提交回复
热议问题