[英]Spring message bundle issue
我的網絡應用程序中有一個彈簧安全設置。 我想用我的自定義消息替換一些關於spring security的消息,即
我希望AbstractUserDetailsAuthenticationProvider.badCredentials
具有invalid username or password, please try again
而不是Bad Credentials
invalid username or password, please try again
這是我的春季設置:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages/messages"/>
<!-- Tried this as well <property name="basename" value="/WEB-INF/messages/messages.properties"/> -->
<property name="cacheSeconds" value="0" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
我已經在WEB-INF
創建了名為messages
文件夾。 在此文件夾中,有一個名為messages.properties
文件。 該文件內是一行:
AbstractUserDetailsAuthenticationProvider.badCredentials=invalid username or password, please try again
我在這里做錯了什么?
更新:
此servlet上下文在web xml中定義:
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
問題解決后,將messageSource bean定義移至另一個上下文。
一切看起來都不錯。 嘗試使用spring message標簽獲取消息,以檢查問題是否與您的配置或安全消息有關:
<spring:message code="AbstractUserDetailsAuthenticationProvider.badCredentials" />
如果此方法有效,則您的配置不存在問題(對我來說不錯)。
無論如何,請嘗試將您的消息文件放在類路徑(源文件夾)中,然后執行以下操作:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages/messages"/>
<property name="cacheSeconds" value="0" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
另外,檢查該bean是否在Spring知道的應用程序上下文文件中聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.