如何获得 Spring 在创建所有其他 bean 之前引导创建一个 bean 验证器

How to get Spring Boot to create a bean validator before creating all the other beans

我正在尝试将 LocalValidatorFactoryBean 添加到现有 Spring 引导 Web 应用程序。

无论我尝试了什么(稍后列出),它只会在大多数其他 bean 之后创建验证器(通过日志记录和断点进行验证),因此它们永远不会得到验证。

切线地,我在 class 路径上有 hibernate-validator 并试图在我的 @Component 属性上使用 javax.validation.constraints。

应用程序 class 有 @Configuration@EnableAutoConfiguration@ComponentScan({"my.package.**"})

在所有情况下,仅在 FilterRegistrationBean 完成记录其业务后才加载验证器,但我要验证的 bean 已经创建并用于设置数据连接和安全性等。

自从我使用 Spring 以来已经有几年了,但我不记得在 application.xml 中定义所有内容时出现的这些问题。这只是 spring-boot 不支持的东西,我应该回到传统的 Spring 应用程序配置吗?

我怎样才能让它验证我所有的 bean?

我忘了做一个 BeanValidationPostProcessor