我想创建使用jakartabean验证框架的普通spring应用程序(不是springboot或springmvc)
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>7.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>4.0.0</version>
</dependency>
尝试使用上述依赖项,但无法使用@notnull@notblank等执行方法/构造函数参数验证。示例
public TestConstructor(@NotNull @NotBlank final String param1, @NotNull @NotBlank final String param2, @NotNull @NotBlank final String param3) {
...
...
}
...
...
public void testMethod(@NotNull @NotBlank final String param1) {
...
}
我创建了下面的bean,只能手动验证对象
@Bean
public Validator validator() {
return Validation.byProvider(HibernateValidator.class).configure().buildValidatorFactory().getValidator();
}
我想使用jakartabean验证框架(而不是javax验证)执行参数和对象的自动验证
暂无答案!
目前还没有任何答案,快来回答吧!