java - Spring Security 国际化消息不会被覆盖

标签 java spring spring-mvc spring-security

您好,我正在尝试覆盖 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/

相关文章:

java - 如何让 Sonarcloud 在来自带有 Travis、Maven 和 github 的 fork 的拉取请求上运行

java - 管理跨服务器实例的共享属性文件

Spring MVC 映射@RequestBody 与包含点的变量

java - spring-data-neo4j 与 Autowired 冲突

java - RAD/Eclipse Eclipse 测试和性能工具平台,将数据导出到文本文件

java - cursor.getCount() 使用 rawQuery 返回错误的计数

java - Android Studio 自定义 ArrayAdapter 传递 HashMap 而不是 ArrayList

java - Log4j2 使用spring时找不到?

java - Resteasy spring 自定义对象映射器

spring - 如何将 Spring Controller 映射到它们的 thymeleaf View (intellij14)