您好,我正在尝试覆盖 Spring 安全性的英语默认消息,但我有一些特定的消息没有收到覆盖消息,这些是我的代码。
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="es_MX"/>
<property name="cookieName" value="gb"/>
<property name="cookieMaxAge" value="4800"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
对于此消息,消息是正确的:
AbstractUserDetailsAuthenticationProvider.badCredentials=La clave de usuario y/o contraseña son incorrectas
jsp中显示的消息是:
La clave de usuario y/o contraseña son incorrectas
但是对于这个:
ConcurrentSessionControlStrategy.exceededAllowed=Esta cuenta ya esta siendo utilizada
我收到此消息:
Maximum sessions of 1 for this principal exceeded
消息在 jsp 中打印如下:
<c:if test="${not empty param.login_error}">
<p class="text-danger text-center"><strong>${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.localizedMessage}</strong></p>
</c:if>
正如您所看到的,该消息在我的自定义消息中已正确翻译,但在应用程序中不正确,有人可以帮助我。
我正在使用下一个库
- Spring 4.1.6.RELEASE
- Spring 安全 3.2.7.RELEASE
- Apache 瓷砖3.0.5
提前致谢。
最佳答案
Spring的Java code中的消息键似乎已更改,但不在 messages bundle 中。您收到英文消息的原因是因为我链接到的 Java 代码中提供了默认消息。
尝试:
ConcurrentSessionControlAuthenticationStrategy.exceededAllowed=Esta cuenta ya esta siendo utilizada
它应该可以工作。
编辑: 甚至在 Spring's JIRA 上创建了一个问题为此。
关于java - Spring Security 国际化消息不会被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32215282/