UTF-8 encoding issues with Spring resourcebundle for special characters
I am using Spring ResourceBundle to retrieve a message bundle from my .properties file. It contains special European characters such as:
Ü, ß. ä, ö, ü
The MessageSouce bean is given below (I'm pretty sure UTF-8 encoding is respected)
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:/META-INF/i18/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
When I try to get a message in my Java code, I get unwanted characters.
If I use below code it helps to recognize a few characters, but the rest are still displayed as
return new String (bundleString.getBytes(), "UTF-8")
Then I used below to encode my properties file but still no effect
native2ascii -encoding utf8 resources.utf8 resources.properties
I also tried to manually open the properties file in Notepad ++ and set the encoding to UTF-8, but no effect. I see a post here having the same problem as mine. But the solution uses the PropertiesBundle property whereas I should only use the Spring solution. However, even the accepted answer in this link does not work for me and gives unnecessary characters.
Please suggest any possible solution.
I had the same problem and @sunny_dev's answer worked for me. I don't understand why there is no answer to this question yet, so I am updating the question.
@sunny_dev's answer:
Karol, I solved the problem by opening and saving the .properties file in TextPad as "UTF-8" encoding and "Unix" platform. I have taken this the same approach, however in Notepad ++ with no positive result previously. - sunny_dev
Thanks again @sunny_dev