Spring Bootで静的ファイルを配置する

静的ファイルを配置する

フォルダー構成

|-build.gradle
`-src/main/resources/
  |-static/
  | `-static.html
  |-public/
  | `-public.html
  |-resources/
  | `-resources.html
  `-META-INF/resources/
    `-m-resourceshtml

各HTMLファイルには、ファイル名を示すプレーンテキストを記述します。

アプリケーションの起動

この構成でSpring Bootを起動し、次のように使用します。

$ curl http://localhost:8080/static.html
static.html

$ curl http://localhost:8080/public.html
public.html

$ curl http://localhost:8080/resources.html
resources.html

$ curl http://localhost:8080/m-resources.html
m-resources.html

静的ファイルへのアクセス

クラスパスの次のフォルダーにファイルを配置すると、静的ファイルとしてアクセスできます。

  • static
  • public
  • resources
  • META-INF/resources