Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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
Maven 验证实体POJO对象_Maven_Spring Mvc - Fatal编程技术网

Maven 验证实体POJO对象

Maven 验证实体POJO对象,maven,spring-mvc,Maven,Spring Mvc,我使用带注释样式的SpringMVC。在我的配置类中,我声明 @Bean("messageSource") public MessageSource getMessageSource() { ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename("classpath:messages")

我使用带注释样式的SpringMVC。在我的配置类中,我声明

@Bean("messageSource")
public MessageSource getMessageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}
“src/main/resources”文件夹包含messages.properties。 我现在要执行的验证是:

@Entity
@Table(name = "contract")
public class Contracts {
        @NotNull
        @Column(name = "payment_amount")
        private Integer paymentAmount;
}
和属性文件中的文本:

NotNull.contracts.paymentAmount = Invalid.
NotEmpty.contracts.paymentAmount = Invalid.
NotBlank.contracts.paymentAmount = Invalid.
NotNull.contracts.paymentamount = Invalid.
NotEmpty.contracts.paymentamount = Invalid.
NotBlank.contracts.paymentamount = Invalid.
但它根本不起作用。最大的问题是我的另一个应用程序在相同(或多或少)设置下工作正常。
因为可能是名称空间问题,我不会添加pom.xml,但maven可能会导致问题,因为这是我目前唯一怀疑的问题。

如果您收到错误消息: 您没有在@NotNull注释中指定键。 在属性文件中指定一个或使用javax.validation.constraints.NotNull.message作为键

如果验证根本没有运行:是否将@Valid放在方法的参数上


如果有其他问题,请指定哪些问题不起作用。

好的,我已经让它起作用了。在对消息进行测试以查看它们是否被Spring看到时,我设法获得了以下信息: 在我的测试文件中:

String message = messageSource.getMessage("NotNull.contracts.startDate", null, Locale.getDefault());
        System.out.println(message);

我没听错。但当我尝试运行我的web应用程序时,我看到的唯一消息都被硬编码到类注释@NotNull(message=”“)中。顺便说一句,为了使测试正常工作,我将messageSource更改为ResourceBundleMessageSource

,并将ModelAttribute有效类名和BindingResults按此顺序排列。当我指定NotNull(message)时,它可以工作,但spring配置似乎丢失了外部文件。