我正在尝试设置一个在我的JSP和控制器中使用的ReloadableResourceBundleMessageSource。这是我手头的碎片。消息键正在打印到我的jsp中的屏幕上。我遗漏了什么?
spring-servlet.xml
<bean id="messages" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<value>/WEB-INF/messages/login</value>
</property>
</bean> login_en.properties
login.title=Welcome to the login page.home.jsp
<body>
<spring:message code="login.title" text="login.title"></spring:message>
</body>发布于 2011-06-09 11:20:26
是的,这也让我被绊倒了很长一段时间。必须将bean id命名为messageSource。
发布于 2014-05-28 01:57:18
我之所以发布我对基于java的配置的答案,是因为当我从xml切换到基于java的配置应用程序时,我遇到了同样的问题,找出它为什么不能工作是一件非常痛苦的事情。(对我来说,这是同样的问题,@jiggy指出…难道你不知道...)
@Bean(name = "validator")
public LocalValidatorFactoryBean getLocalValidatorFactoryBean() {
final LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource(this.getMessageSource());
validator.afterPropertiesSet();
return validator;
}
@Bean(name = "messageSource") // --> !!! This is what is so important!!!
public MessageSource getMessageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); // easily swapped out with "ReloadableResourceBundleMessageSource", my app just doesn't have any necessary reloadable message requirements.
messageSource.setBasenames(ERROR_MESSAGE_DIRECTORY); // static String for a direct path to your "ValidationMessages.properties" file or whatever name you've given it.
return messageSource;
}发布于 2011-11-21 05:16:17
另外,不要忘记广泛地声明messageSource应用程序,而不是在servlet spring bean中声明。
https://stackoverflow.com/questions/6287632
复制相似问题