Java Spring 4 MVC JSR303@Valid错误消息到属性

Java Spring 4 MVC JSR303@Valid错误消息到属性,java,spring,Java,Spring,正在尝试将我的所有错误消息都包含在属性中 以下教程: 问题:错误消息不是来自我的属性文件。不知道我做错了什么 文件结构: 波乔 例外情况 NotNull.book.name = Book name must not be blank, Please insert valid book name. Size.book.name = Book name should have more than 7 characters. NotNull.book.ispn = Must enter valid

正在尝试将我的所有错误消息都包含在属性中

以下教程:

问题:错误消息不是来自我的属性文件。不知道我做错了什么

文件结构:

波乔

例外情况

NotNull.book.name = Book name must not be blank, Please insert valid book name.
Size.book.name = Book name should have more than 7 characters.

NotNull.book.ispn = Must enter valid ISPN code.
Size.book.ispn = Standard ISPN code should have 10, 13 characters.

DecimalMin.book.price = Price of the book must be greater than 0. And can not be Negative number.
app-dispatcher-servlet.xml

<context:component-scan base-package="com.app.controller" />

<mvc:annotation-driven/>

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>

<mvc:interceptors>
    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="language" />
    </bean>
</mvc:interceptors>

<!-- Binding properties to context -->

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>com.app.properties.windows</value>
            <value>com.app.properties.exceptions</value>
        </list>
    </property>

</bean>

com.app.properties.windows
com.app.properties.exceptions
我做错了什么?非常感谢你的额外眼睛


谢谢

我认为您的消息源配置错误。试着这样做:

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>classpath:window</value>
            <value>classpath:exception</value>
        </list>
    </property>
</bean>

类路径:窗口
类路径:异常

结果是
异常。属性不应引用类和字段,而应引用由commandName或modelAttribute提供的表单和路径名、表单名

这是我的HTML

<sf:form action="/newbook" modelAttribute="formBook" method="POST">
        <table>
        <tr>
            <td>Book Name:</td>
            <td>
                <sf:input type='text' name='name' path="name"/><br/>
                <sf:errors path="name"></sf:errors>
            </td>
        </tr>
        <tr>
            <td>ispn:</td>
            <td>
                <sf:input type='text' name='ispn' path="ispn"/><br/>
                <sf:errors path="ispn"></sf:errors> 
            </td>
        </tr>
        <tr>
            <td>Price:</td>
            <td>
                <sf:input type='text' name='price' path="price"/><br/>
                <sf:errors path="price"></sf:errors>

            </td>
        </tr>
        <tr><td colspan='2'><input name="submit" type="submit" value="submit"/></td></tr>

        </table>
    </sf:form>

希望这能帮助其他人。。。花了我很长时间…

我认为值应该是限定名称。。。编辑:我试过了,但没用。当我执行此操作时,window.properties未加载。。。。。你需要我对我的文件夹进行屏幕截图吗?那会有帮助吗?好的,请这样做。非常感谢你花时间我上传了文件结构。。。我的代码看起来没什么问题?我能把它发送到我的邮箱吗?谢谢,因为我的eclipse插件总是没有安装
<sf:form action="/newbook" modelAttribute="formBook" method="POST">
        <table>
        <tr>
            <td>Book Name:</td>
            <td>
                <sf:input type='text' name='name' path="name"/><br/>
                <sf:errors path="name"></sf:errors>
            </td>
        </tr>
        <tr>
            <td>ispn:</td>
            <td>
                <sf:input type='text' name='ispn' path="ispn"/><br/>
                <sf:errors path="ispn"></sf:errors> 
            </td>
        </tr>
        <tr>
            <td>Price:</td>
            <td>
                <sf:input type='text' name='price' path="price"/><br/>
                <sf:errors path="price"></sf:errors>

            </td>
        </tr>
        <tr><td colspan='2'><input name="submit" type="submit" value="submit"/></td></tr>

        </table>
    </sf:form>
NotNull.formBook.name = Book name must not be blank, Please insert valid book name.
Size.formBook.name = Book name should have more than 7 characters.

NotNull.formBook.ispn = Must enter valid ISPN code.
Size.formBook.ispn = Standard ISPN code should have 10, 13 characters.