【发布时间】:2011-09-28 04:18:51
【问题描述】:
我卡住了,可能错过了文档中的某些内容或犯了一些小错误。
Spring Security 3.0.5 已集成到我的 Spring MVC 3.0.5 应用程序中。 AcceptHeaderLocaleResolver 用于区域设置检测和本地化工作正常,但安全错误消息除外。
我从 spring 安全包中复制了 messages.properties 并重命名并添加到现有的 "messageSource" bean (ResourceBundleMessageSource) 与值列表。
如前所述,所有文本和消息都已正确本地化,除了使用硬编码英文消息的安全接缝。
有什么办法解决这个问题吗?
更新:
我的 xy-servlet.xml 包含:
...
<mvc:resources mapping="/resources/**" location="/resources/" />
...
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>defaultMessages</value>
<value>securityMessages</value>
</list>
</property>
</bean>
和文件
defaultMessages.propertiesdefaultMessages_en.propertiesdefaultMessages_de.propertiesdefaultMessages_sl.properties
和
securityMessages.propertiessecurityMessages_en.propertiessecurityMessages_de.propertiessecurityMessages_sl.properties
但是defaultMessages 工作正常。 securityMessages 没有。我对所有 securityMessages 文件进行了小改动,但它们被忽略了,并且显示了硬编码的英文消息。
更新 v2:
我的 dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<context:component-scan base-package="com.example.sampleapp1" />
<context:annotation-config />
<mvc:annotation-driven/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>defaultMessages</value>
<value>securityMessages</value>
<value>org/springframework/security/messages_de</value>
</list>
</property>
</bean>
<!-- Persistence -->
<bean id="myPMF" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
<property name="persistenceManagerFactoryName" value="transactions-optional"/>
</bean>
<!-- Form Validator -->
</beans>
【问题讨论】:
标签: java spring spring-mvc internationalization spring-security