A note about static file access in spring-boot.
spring boot is the default setting,
projectDirectory/src/main/resources/META-INF/resources/
projectDirectory/src/main/resources/
projectDirectory/src/main/resources/static/
projectDirectory/src/main/resources/public/
By placing it below, access is possible.
As an example, When HTML is placed in each directory as shown below
project root
  └─ src
      └─ main
          └─ resources
              ├─ static
              |   └─ html
              |       └─ 1.html
              ├─ public
              |   └─ html
              |       └─ 2.html
              ├─ resources 
              |   └─ html
              |       └─ 3.html
              └─ META-INF
                  └─ resources
                      └─ html
                          └─ 4.html
To each HTML,
http://localhost:8080/1.html
http://localhost:8080/2.html
http://localhost:8080/3.html
http://localhost:8080/4.html
It becomes possible to access in the form of.
When a file with the same name exists in each directory as shown below
project root
  └─ src
      └─ main
          └─ resources
              ├─ static
              |   └─ html
              |       └─ test.html
              ├─ public
              |   └─ html
              |       └─ test.html
              ├─ resources 
              |   └─ html
              |       └─ test.html
              └─ META-INF
                  └─ resources
                      └─ html
                          └─ test.html
When you access http: //localhost:8080/test.html,
META-INF / resources / html / test.html is returned
The search order for static files is
resources/META-INF/resources/resources/resources/static/resources/public/The search is performed in the order of, and the one found first is returned on the screen.
resources/META-INF/resources/resources/Does not seem to be suitable for placing static files, as it also contains configuration files.
When actually using it in a project,
resources/static/resources/public/I think it will be placed in.
By name,
Something that doesn't change, such as a library, in resources / static /.
resources / public / Place project-specific css, js, etc.
Is it like that? .. ..
Hmmm. I don't know what is best practice around here, so I don't know if this is all right. Someone who teaches and knows (; ∀ ;)
Recommended Posts