Spring 没有找到 messages.properties
Spring does not find messages.properties
我正在使用 Spring 框架开发一个 Maven 项目。
我更喜欢使用 <spring:message .../>
标记并在 .properties 文件中注册我的消息,而不是在 JSP 中编写原始文本。
我在请求页面时收到此警告:
ResourceBundle [messages] not found for MessageSource: Can't
find bundle for base name messages, locale 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>
The basenames follow ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.
(强调我的)
所以应该在src/main/resources
.
下
我正在使用 Spring 框架开发一个 Maven 项目。
我更喜欢使用 <spring:message .../>
标记并在 .properties 文件中注册我的消息,而不是在 JSP 中编写原始文本。
我在请求页面时收到此警告:
ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale 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>
The basenames follow ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.
(强调我的)
所以应该在src/main/resources
.