Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未检测到Spring MessageSource属性文件的第一行_Java_Spring - Fatal编程技术网

Java 未检测到Spring MessageSource属性文件的第一行

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

我使用Spring4并使用MessageSource进行本地化

我的xml文件有:

<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