Spring Boot で Velocity を使ったら、日本語の文字化けが発生しました。今回は、文字化けが解消した方法を書いていこうと思います。
文字化けの発生条件
次の2点を満たしていると、文字化けが発生するようです。
対応方法
Spring Boot の設定ファイル(application.properties 等)で、Velocity のエンコーディングを UTF-8 などに変更します。
spring.velocity.properties.input.encoding=UTF-8 spring.velocity.properties.output.encoding=UTF-8
補足1. Velocity のデフォルトエンコーディング
Velocity の jar の中にある velocity.properties で定義されてるようです。
input.encoding=ISO-8859-1 output.encoding=ISO-8859-1
補足2. SpringBoot を使っていない場合
WEB-INF 配下に velocity.properties を用意して、設定を上書きすると良いみたいです。
input.encoding=UTF-8 output.encoding=UTF-8