Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc Spring mvc无法读取messages.properties文件_Spring Mvc_Spring Validator - Fatal编程技术网

Spring mvc Spring mvc无法读取messages.properties文件

Spring mvc Spring mvc无法读取messages.properties文件,spring-mvc,spring-validator,Spring Mvc,Spring Validator,我试图通过使用属性文件来使用自定义验证错误消息。我已将messages.properties文件放在web内容/web inf/文件夹中 NonEmpty.batchDomain.batchName=Invalid message 2. 我的applicationContext文件是: <context:component-scan base-package="com.coaching.controller" /> <!-- Enable annotat

我试图通过使用属性文件来使用自定义验证错误消息。我已将messages.properties文件放在web内容/web inf/文件夹中

    NonEmpty.batchDomain.batchName=Invalid message 2.
我的applicationContext文件是:

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

<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views 
    directory -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">



    <property name="prefix">
        <value>/WEB-INF/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
<mvc:default-servlet-handler />
<mvc:resources mapping="/resources/**" location="/resources/" />

<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

    <property name="basename" value="/WEB-INF/messages" />

</bean>
BatchDomain是:

       public class BatchDomain {

@NotNull
@NotEmpty
@Size(min = 1, max = 100)
private String batchName;

@Min(1)
@Max(1000)
private int strength;

 }

就我在谷歌所见,我遵循的是正确的方法。那么,这个问题背后的原因是什么呢?

您可以尝试将文件“messages.properties”放在/src/main/resource目录中

您是否可以尝试将属性文件放在类路径的根目录下,而不是放在
WEB-INF
中?在spring上下文中也更改声明。我已按照将该文件放置在src文件夹中,并已将上下文文件编辑为,但未发生任何事情。您的messages.properties文件在其他情况下有效,但在验证消息中被忽略,还是在任何情况下都无效?您可能正在使用hibernate validator查找ValidationMessages.properties(除非另有配置)。我正在使用import javax.validation.constraints和org.springframework.format.annotation.*验证。我将messages.properties仅用于验证错误。
       public class BatchDomain {

@NotNull
@NotEmpty
@Size(min = 1, max = 100)
private String batchName;

@Min(1)
@Max(1000)
private int strength;

 }