是否可以使用@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