[转载]spring使用PropertyPlaceholderConfigurer加载properties文件处理中文乱码

在spring中我们常常使用.properties对一些属性进行一个提前配置,spring在读取∗.properties文件时,默认使用的是asci码,这时我们需要对其编码进行转换.当然方法有很多种,我说以下几种

1.spring.xml,.properties使"utf8"

<context:property-placeholder location="classpath:conf/*.properties" file-encoding="UTF-8"/>

2.使:

@Component
@PropertySource(value = "classpath:conf/copyWriteUI.properties",encoding = "utf-8")
@Getter
public class CopyWriteUI {
    @Value("${a}")
    private String a;
    @Value("${b}")
    private String b;
    }

转自:http://blog.csdn.net/j3oker/article/details/53839210

 

3.使用PropertyPlaceholderConfigurer配置编码格式

<bean id="resourceConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/config.properties</value>
                <value>classpath:/send.properties</value>
            </list>
        </property>
        <property name="fileEncoding">
            <value>UTF-8</value>
        </property>
    </bean>

 

posted @ 2017-07-20 16:33  weiwei5987  阅读(646)  评论(0编辑  收藏  举报