■Thymeleaf の小径 |
2-3)Thymeleaf ver3.x系の導入について |
Thymeleafのバージョンを、2.x系から、3.x系にバージョンアップしてみたところ、 変更点があるようなので、気が付いたことを記録しておきます。 ちなみに、Thymeleafのバージョン変更は、pom.xmlで設定します。 pom.xml <thymeleaf.version>2.1.3.RELEASE</thymeleaf.version> ↓ <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> 詳しくは、「■SpringMVC の小径 1-3)pom.xmlの編集」を参照してください。 1)th:substitutebyタグの非推奨化(?) Thymeleafで、JSPの <jsp:include page='xx'/>とか、JSTLの<c:import url="" /> に相当する、別ファイルを読み込むためのth:substitutebyタグですが、Thymeleaf ver3.x系から、変更になったようです。 th:substitutebyでも動作自体は問題なく成功しますが、ログを確認していると、 WARN - [THYMELEAF][http-nio-8080-exec-3][HTMLテンプレート名] Deprecated attribute {th:substituteby,data-th-substituteby} found in template HTMLテンプレート名, line 124, col 9. Please use {th:replace,data-th-replace} instead, this deprecated attribute will be removed in future versions of Thymeleaf. といった感じの警告ログが出力されるようになりました。 対策としては、th:substitutebyタグを、th:replace タグに変更すれば出力されなくなります。 教訓:Thymeleaf ver3.x系では、th:replace を使うべし。 でも、実はかなり随所でth:substitutebyを使ってるんだよなぁ。。。 まぁ、Eclipseで一括置換すればいい話だけどね! 2)Thymeleaf テンプレートリゾルバの変更(2016/Oct/09 追記) Spring-MVC設定ファイル(applicationContext.xml)でこれまでの2.x系で宣言していた テンプレートリゾルバですが、3.x系から変更になったようなので変更点を記録しておきます。 WebContent/WEB-INF/applicationContext.xml 旧) <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> 新) <bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"> Thymeleafを最新の3.0.2 に入れ替えて、EclipseNeonから導入されたLiveReload プラグインを設定してみたところ、 applicationContext.xmlの、ここの部分で問題ビューにエラーが表示されました。 動作自体は一応動作しますが、気持ちが悪いので調べてみたところ、 ServletContextTemplateResolverクラスは、 3.x系からデフォルトコンストラクタが引数としてServletContextを要求するようになったため エラーが表示される様です。 3.x系では、SpringResourceTemplateResolverクラスを使うようにしましょう。 Thymeleafを3.x系に変更する際は注意してください。 参考)LiveReload プラグイン:Eclipse 4.6 Neon 新機能 TOP10!と Spring Boot STS |
2-2)input password属性の注意点 ![]() |
Thymeleaf ver3.x系の導入について |