Java 未检测到Spring MessageSource属性文件的第一行
我使用Spring4并使用MessageSource进行本地化 我的xml文件有:Java 未检测到Spring MessageSource属性文件的第一行,java,spring,Java,Spring,我使用Spring4并使用MessageSource进行本地化 我的xml文件有: <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:i18n/myfile"/> <property name="defa
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/myfile"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
获取本地化字符串的Java代码为:
@Autowired
private MessageSource messageSource;
String localizedMsg = messageSource.getMessage("prop1", null, locale);
现在,我得到一个异常,prop1没有找到。
因此,我编辑了属性文件,以便稍后在文件中复制prop1
other1=o1
other2=o2
prop1=abc
other3=o3
现在检测到prop1
为什么prop1在第一行时没有被检测到?在UTF-8中,您的属性文件可能以BOM()开头 由于Java不执行BOM表,因此将作为不可显示的BOM字符处理,并成为第一行中列出的属性名称的一部分,这当然会使其不匹配 在文本编辑器中编辑文件,该编辑器可以在不使用BOM表的情况下保存文件 记事本++就是这样一个文本编辑器的例子。请参阅:
other1=o1
other2=o2
prop1=abc
other3=o3