私は立ち往生していますが、おそらくドキュメントに何かが見当たらなかったり、小さな間違いがありました。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 k ok。 securityMessages
はありません。 securityMessages
すべてのファイルに小さな変更を加えましたが、無視され、ハードコードされた英語のメッセージが表示されます。
UPDATE v2の: 私のディスパッチャ-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