2

アプリケーションの検証プロセスでは、message.propertiesファイルを使用してカスタムメッセージを表示しました。しかし、それは機能しておらず、AppEngineサーバーログに次のエラーが表示されます

org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag:ロケール「en_US」のコード「notmatch.password」の下にメッセージが見つかりません。org.springframework.context.NoSuchMessageException:ロケール'en_US'のコード'notmatch.password'の下にメッセージが見つかりません。

検証用の私のコードは次のとおりです。

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");
    }

}

私の構成xmlは次のとおりです。

<?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>

私のプロジェクトファイルの構造は画像に示されています

4

2 に答える 2

4

次のようなファイル にnotmatch.passwordキーがあることを確認してくださいmessage_en_US.properties

notmatch.password = Inccorect password

ベース名を次のように変更します

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

詳細については、このリンクを確認してください。

于 2012-09-04T09:09:30.450 に答える
1

コンテキストで PropertyPlaceholder を構成します。

<context:property-placeholder locations="classpath*:my.properties"/>

詳細については、この投稿も確認してください。

プロパティファイルから値を読み取る方法は?

于 2012-09-04T05:29:40.823 に答える