End to end UTF-8 encoding usage with MySql and Spring – Part 2

1 min read >

End to end UTF-8 encoding usage with MySql and Spring – Part 2

Engineering Insights & Enterprise solutions

One thing I forgot to mention was the usage of Spring message bundles. Usually, a ResourceBundleMessageSource is configured to inject bundle messages for Spring MVC. The only bad thing is that I could not specify an encoding for the configured message.properties files. As the default properties format is ISO 8859-1 character encoding and tedious operations like the transformation of Unicode characters using native2ascii tool are necessary, I looked for a way to load UTF-8 resource files without any transformations. Spring has a ReloadableResourceBundleMessageSource class that allows just that, along with the reloadable behavior. The bundle configuration now looks:

<bean id=”messageSource” class=”org.springframework.context.support.ReloadableResourceBundleMessageSource”>

<property name=”basename”>

<value>/WEB-INF/classes/messages</value>

</property>

<property name=”defaultEncoding”>

<value>UTF-8</value>

</property>

<property name=”cacheSeconds”>

<value>-1</value>

</property>

</bean>