<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cake Solutions Team Blog &#187; utf-8</title>
	<atom:link href="http://www.cakesolutions.net/teamblogs/tag/utf-8/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cakesolutions.net/teamblogs</link>
	<description>void magic() { }</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>UTF-8 encoding and Spring message sources</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=utf-8-encoding-and-message-sources</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 13:59:49 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[MessageSource]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=113</guid>
		<description><![CDATA[Take a look at the update from October 2011&#8242;s perspective here. I was working on a pretty much straight-forward web application. As usual, i used Spring&#8217;s org.springframework.context.MessageSourcesupport, to be more precise, i used standard implementation &#8211; ResourceBundleMessageSource. Simple configuration, as &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Take a look at the update from October 2011&#8242;s perspective <a href="http://www.cakesolutions.net/teamblogs/2011/11/08/utf-8-encoding-revisited/" title="UTF-8 encoding revisited">here</a>.</p>
<p>I was working on a pretty much straight-forward web application. As usual, i used Spring&#8217;s org.springframework.context.MessageSourcesupport, to be more precise, i used standard implementation &#8211;  ResourceBundleMessageSource. Simple configuration, as following:</p>
<pre>&lt;bean id="messageSource"
                 class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="messages"/&gt;
&lt;/bean&gt;
</pre>
<p>My messages properties file was standard as well, country names, so i had something like this:</p>
<pre>country.name.unitedkindom=UK
country.name.ireland=Ireland
country.name.belgium=België
country.name.iceland=Ísland
country.name.israel=Israel...</pre>
<p>As you can guess, the problems developed with specific characters in country names(ë, Í&#8230;). When i run the application, i got &#8216;???&#8217; characters instead of specific UTF-8 characters for countries (so &#8216;België&#8217; become &#8216;Belgi???&#8217;).</p>
<p>After some research, and digging in Spring source code, i located the problem, and the solution!</p>
<p>The problem was that ResourceBundleMessageSource uses the standard  java.util.ResourceBundle and<br />
java.util.Properties, which only support ISO-8859-1 encoding &#8211; so no UTF-8 encoding, no support for any special French, Spanish or Asian characters.</p>
<p>The solutions is very simple, and it comes with Spring as well. Use ReloadableResourceBundleMessageSource instead! Here is the correct configuration:</p>
<pre>&lt;bean id="messageSource";
                     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
         &lt;property name="basename" value="classpath:messages"/&gt;
         &lt;property name="defaultEncoding" value="UTF-8"/&gt;
&lt;/bean&gt;</pre>
<p>As you can see, we are now able ot set default encoding explicitelly, so the countries names in my example worked like charm. The only other change was that the basename is now specified as Resource, so i was able to use convenient classpath: identifier to specify my messages.properties wherever i need it in the source code</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

