2017-02-25 72 views
0

我正在使用Spring框架開發一個maven項目。Spring未找到messages.properties

不用在JSP中編寫原始文本,我更願意使用<spring:message .../>標記並將我的消息註冊到.properties文件中。

資源包[消息]沒有發現的MessageSource:無法找到 捆綁的基本名稱的消息,區域fr

然後帶來

我請求頁面時,得到這樣的警告關於消息未被發現的例外(顯然)。

這裏是我的項目的層次:

my project's hierarchy

這裏是我的springapp-servlet.xml中:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
         http://www.springframework.org/schema/mvc 
         http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
         http://www.springframework.org/schema/aop 
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 

<context:component-scan base-package="app.core" /> 

<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/jsp/"> 
    </property> 
    <property name="suffix" value=".jsp"> 
    </property> 
</bean> 

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> 
    <property name="defaultLocale" value="fr" /> 
</bean> 

<bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>messages</value> 
     </list> 
    </property> 
</bean> 

<mvc:resources mapping="/public/**" location="/WEB-INF/resources/" 
       cache-period="31556926"/> 

<mvc:annotation-driven /> 

</beans> 

回答

1

the documentation

的基本名稱遵循資源包約定:從本質上講,一個完全合格的classpath位置。如果它不包含包限定符(如org.mypackage),它將從類路徑 root解析出來。

(重點煤礦)

所以應該src/main/resources下。

+0

它的工作!謝謝 !即使我的IDE(intellij idea)警告了基本名稱值。 –

相關問題