Where to put static files such as CSS in a spring-boot project?

后端 未结 10 2059
猫巷女王i
猫巷女王i 2020-12-02 09:47

In my current spring-boot project, my views have this line:


to reference a static css

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 10:32

    Anywhere beneath src/main/resources/static is an appropriate place for static content such as CSS, JavaScript, and images. The static directory is served from /. For example, src/main/resources/static/signin.css will be served from /signin.css whereas src/main/resources/static/css/signin.css will be served from /css/signin.css.

    The src/main/resources/templates folder is intended for view templates that will be turned into HTML by a templating engine such as Thymeleaf, Freemarker, or Velocity, etc. You shouldn't place static content in this directory.

    Also make sure you haven't used @EnableWebMvc in your application as that will disable Spring Boot's auto-configuration of Spring MVC.

提交回复
热议问题