• [转载]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>
  • 相关阅读:
    MySQL补充
    不同操作系统下虚拟环境的搭建
    Python导学基础(二)变量与基础数据类型
    Python导学基础(一)介绍
    KM 算法
    题解-CF1065E Side Transmutations
    题解-CF1140E Palindrome-less Arrays
    题解-CF677D Vanya and Treasure
    splay文艺平衡树
    splay区间操作(bzoj1500)
  • 原文地址:https://www.cnblogs.com/wendelhuang/p/7211966.html
Copyright © 2020-2023  润新知