I'm working on converting some properties files from iso-8859-1 to utf-8. I implemented a resource.control for most resource files so that it would read as utf-8 encoding.
I came across a properties file that was defined in spring using the util:properties tag.
I was wondering if there is a way to specify that the default encoding be utf-8? I did look at the possibility defining this as a bean with the ReloadableResourceBundleMessageSource, however that would require a big refactoring process, since the logic in the bean expects this to be as a map.
defined using spring 3.0.5
<util:properties id="fooProperties" location="file:${AXE_APPCONFIG}/foo.properties"/>
I know that by definition java properties files are iso-8859-1 encoded, however I thought that spring might have come up with a way to change the encoding of it (like the Resource.Control)
I have recently solved the same problem by using PropertiesFactoryBean. It is a subclass of PropertiesLoaderSupport, which has a public setter method for you to specify encoding of your property file.
<beans:bean id="nameOfYourPropsVar" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<beans:property name="location" value="classpath:${yourPropFileName}"/>
<beans:property name="fileEncoding" value="UTF-8"/>
</beans:bean>
Please note that according to the api doc, it only applies to classic properties file, not to XML files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With