Spring:message.properties 文件不起作用 [英] Spring : message.properties file not working

查看:41
本文介绍了Spring:message.properties 文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序验证过程中,我使用了message.properties 文件来显示自定义消息.但它不起作用,并在 App Engine 服务器日志中显示以下错误

<块引用>

org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag:在语言环境的代码notmatch.password"下找不到消息'en_US'.org.springframework.context.NoSuchMessageException:否在区域设置en_US"的代码notmatch.password"下找到消息.

我的验证代码是:

public void validate(Object target, Errors 错误) {ValidationUtils.rejectIfEmptyOrWhitespace(错误,密码","required.password", "字段名是必填项.");ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword","required.confirmPassword", "字段名是必填项.");NewUser cust = (NewUser) 目标;如果 (!(cust.getPassword().equals(cust.getConfirmPassword()))) {errors.rejectValue("password", "notmatch.password");}}

我的配置xml是:

<beans:property name="basename"value="/WEB-INF/resources/message_en_US.properties"/></beans:bean><beans:bean name="/register" class="com.my.registration.NewUserRegistration"><beans:property name="验证器"><beans:bean class="com.my.validation.UserValidator"/></beans:property><beans:property name="formView" value="newuser"></beans:property><beans:property name="successView" value="home"></beans:property></beans:bean>

解决方案

确保您在 message_en_US.properties 文件中有 notmatch.password 键,例如

notmatch.password = 密码错误

并将基本名称更改为

有关更多信息,请查看此链接.>

In my validation process of application, i used message.properties file to show custom message. But it is not working and shows the following error in App Engine server log as

org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag: No message found under code 'notmatch.password' for locale 'en_US'. org.springframework.context.NoSuchMessageException: No message found under code 'notmatch.password' for locale 'en_US'.

My code for validation is :

public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
            "required.password", "Field name is required.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword",
            "required.confirmPassword", "Field name is required.");

    NewUser cust = (NewUser) target;

    if (!(cust.getPassword().equals(cust.getConfirmPassword()))) {
        errors.rejectValue("password", "notmatch.password");
    }

}

My configuration xml is :

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <beans:bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <beans:property name="basename"
            value="/WEB-INF/resources/message_en_US.properties" />
    </beans:bean>



        <beans:bean name="/register" class="com.my.registration.NewUserRegistration">
        <beans:property name="validator">
            <beans:bean class="com.my.validation.UserValidator" />
        </beans:property>
        <beans:property name="formView" value="newuser"></beans:property>
        <beans:property name="successView" value="home"></beans:property>
    </beans:bean>

解决方案

Make sure you have notmatch.password key in message_en_US.properties file like

notmatch.password = Inccorect password

and change the basename to

<beans:property name="basename"
            value="/WEB-INF/resources/message" />  

For more information check this link.

这篇关于Spring:message.properties 文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆