在代码'avatar.path'下找不到区域设置'ru_RU'的消息。春天的错误

时间:2012-08-10 17:58:22

标签: spring

我的代码

    private ApplicationContext context;

    @Autowired
    public UserServiceImpl(ApplicationContext context) {
    this.context = context;
    }
     ...     
     Locale bundle = new Locale.Builder().setLanguage("ru").setRegion("RU").build(); 
     String av = context.getMessage("avatar.path", null, bundle);

错误:在代码'avatar.path'下找不到区域设置'ru_RU'的消息。

beans.xml

<beans:bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <beans:property name="basename" value="messages"> </beans:property>
 </beans:bean>

文件夹src / main / resources /

中的messsages_ru_RU.properties
avatar.path = resources/image/avatar.jpg

2 个答案:

答案 0 :(得分:0)

该文件不应该在WEB-INF中吗?

您可以指定您喜欢的任何值,但我认为它必须与WEB-INF相关: 下面的示例对我有用。

 <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
      <property name="basename" value="/WEB-INF/messagesT" />
</bean>

答案 1 :(得分:0)

您可以尝试使用文件名messages_ru_RU.properties