LoginSignup
9
10

More than 5 years have passed since last update.

Spring Boot 1.4+Thymeleaf 3.0でSpELコンパイラを有効にしてパフォーマンスを向上させよう!!

Last updated at Posted at 2016-10-26

以前の投稿で「Spring Boot 1.4でThymeleaf 3.0系を使うための設定方法」を紹介しましたが、Thymeleaf-Spring 3.0からSpELのコンパイラを有効にするオプションが追加され、SpELのコンパイラを有効にすることでテンプレートファイルに指定する式を評価する速度が向上するみたいです。Git HubのIssueには、35%程度のパフォーマンス向上を得ることができたという旨のコメントが記載されていました。(どの程度向上するかは、式の数や使い方に依存すると思うますが・・・)

検証バージョン

  • Spring Boot 1.4.1.RELEASE
  • Thymeleaf 3.0.2.RELEASE
  • Thymeleaf-Spring 3.0.2.RELEASE

オプションの有効化

オプションを有効化したい場合は、Java Configクラスの内にSpringTemplateEngineをインジェクションするメソッドを用意し、インジェクションされたSpringTemplateEnginesetEnableSpringELCompilerメソッドにtrueを渡すだけです:smile:

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    // ...

    @Autowired
    void configureThymeleafSpringTemplateEngine(SpringTemplateEngine templateEngine) {
        templateEngine.setEnableSpringELCompiler(true); // trueを指定!!
    }

}

まとめ

パフォーマンスが改善されたか測定もしてないし、体感もできませんでしたが:sweat_smile:・・・・デバッガ使ってSpELのコンパイラが有効になっていることは確認できました:thumbsup:
現時点のSpring Bootのバージョンではプロパティを使ってカスタマイズすることはできませんが、Spring Bootで扱うThymeleafのデフォルトバージョンが3.0系になったら、プロパティでカスタマイズできるようにPRしようかな〜と思っています。(Spring Bootのdeveloperさんが対応してくれちゃう気もしてますが:blush:

参考サイト

9
10
0

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
9
10