小编and*_*lva的帖子

@PropertySource和UTF-8属性文件

是否可以使用@PropertySource注释配置必须用于加载属性文件的编码?

一个澄清我的问题的例子

@Configuration
@PropertySource("classpath:/myprop.properties")
public class MyApplicationContext {

    @Autowired(required = true)
    private Environment env;

    @Bean
    public MyBean myBean() {
       return new MyBean(env.getRequiredProperty("application.name"));
    }

}
Run Code Online (Sandbox Code Playgroud)

myprop.properties是一个UTF-8文件,但无论如何,"application.name"被解释为ISO-8859-1.

解决方法是在属性文件中转义特殊字符,但是设置编码是可能的,context:property-placeholder所以我认为应该可以做同样的@PropertySource

spring utf-8 character-encoding

5
推荐指数
2
解决办法
5316
查看次数

标签 统计

character-encoding ×1

spring ×1

utf-8 ×1