LoginSignup
10
9

More than 5 years have passed since last update.

Spring Boot + Thymeleaf BootStrap導入方法メモ

Last updated at Posted at 2019-02-08

thymeleafテンプレートエンジンを使用したアプリケーションでのbootstrapの導入に躓いたので、今後のためにも簡単にメモ

webjarsなるものをpomファイルに記述する
xml:pom.xml
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.2.1</version>
</dependency>

htmlファイルでcssを読み込む
ハマったところ1
thymeleafを使っている場合は
th:href="@{webjars/bootstrap/バージョン/css/bootstrap.min.css}" とする。

ハマったところ2
セキュリティを入れている場合はwebjarsへのアクセスを許可しておかなければいけない。

public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/webjars/**");
}

番外
自前でcssを用意するにはsrc/main/resourcesにstaticフォルダを用意して配置しないと読み込んでくれないようです。

10
9
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9