Tôi bị kẹt, có thể đã bỏ sót điều gì đó trong tài liệu hoặc đã phạm một số sai lầm nhỏ.Bảo mật mùa xuân với AcceptHeaderLocaleResolver và i18n
Bảo mật mùa xuân 3.0.5 được tích hợp trong ứng dụng Spring MVC 3.0.5 của tôi. AcceptHeaderLocaleResolver được sử dụng để phát hiện Locale và nội địa hóa hoạt động ok ngoại trừ các thông báo lỗi bảo mật.
Tôi đã sao chép thư.properties từ gói bảo mật mùa xuân và được đổi tên và được thêm vào bean hiện tại "messageSource" (ResourceBundleMessageSource) với danh sách giá trị.
Như đã nói trước đó tất cả văn bản và tin nhắn được bản địa hóa chính xác, ngoại trừ các đường nối bảo mật để sử dụng các tin nhắn tiếng Anh được mã hóa cứng.
Bất kỳ ý tưởng nào về cách giải quyết vấn đề này?
UPDATE:
My xy-servlet.xml chứa:
...
<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>
và các tập tin
defaultMessages.properties
defaultMessages_en.properties
defaultMessages_de.properties
defaultMessages_sl.properties
và
securityMessages.properties
securityMessages_en.properties
securityMessages_de.properties
securityMessages_sl.properties
nhưng defaultMessages
wor k ok. securityMessages
thì không. Tôi đã thực hiện các thay đổi nhỏ trong tất cả các tệp securityMessages
nhưng chúng bị bỏ qua và các thông báo bằng tiếng Anh được mã hóa cứng được hiển thị.
CẬP NHẬT v2: My phối-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>
Tôi không có nhiều kinh nghiệm với Spring MVC và tôi không biết rằng tệp 'xy-servlet.xml' không phải là tệp cấu hình ngữ cảnh của ứng dụng. Dù sao tôi rất vui vì nó đã hoạt động. – bluefoot
Tôi đang sử dụng Spring 3.2 và dường như phải đối mặt với cùng một vấn đề này, nhưng tiếc là giải pháp này dường như không hoạt động đối với tôi. – Ryan