我被卡住了,可能錯過了文檔中的某些東西或者犯了一些小錯誤。Spring Security with AcceptHeaderLocaleResolver和i18n
Spring Security 3.0.5被集成到我的Spring MVC 3.0.5應用程序中。 AcceptHeaderLocaleResolver用於區域設置檢測和本地化工作正常,除了安全錯誤消息。
我複製spring安全包中的messages.properties並重命名並添加到現有的帶有值列表的「messageSource」bean(ResourceBundleMessageSource)。
如前所述,所有文本和消息都已正確本地化,除了安全性接口使用硬編碼的英文消息。
任何想法如何解決這個問題?
UPDATE:
我的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.properties
defaultMessages_en.properties
defaultMessages_de.properties
defaultMessages_sl.properties
和
securityMessages.properties
securityMessages_en.properties
securityMessages_de.properties
securityMessages_sl.properties
但defaultMessages
WOR好的。 securityMessages
沒有。我對所有securityMessages
文件進行了小的更改,但忽略它們並顯示硬編碼的英文消息。
更新版: 我的調度員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>
我對Spring MVC沒有多少經驗,我不知道文件'xy-servlet.xml'不是應用程序上下文配置文件。無論如何,我很高興它的工作。 – bluefoot
我使用的是Spring 3.2,似乎也面臨同樣的問題,但不幸的是,這個解決方案似乎不適合我。 – Ryan