问题就在这里。直到 Spring Boot 2.0.0.M7/Spring 5.0.3(我们的最后一个堆栈),一切都运行良好。
现在升级到 Spring Boot 2.0.0.RC/Spring 5.0.4 我们得到:
Caused by: javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:291)
at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:53)
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator$Delegate.<init>(ConfigurationPropertiesJsr303Validator.java:71)
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator.<init>(ConfigurationPropertiesJsr303Validator.java:43)
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator.getIfJsr303Present(ConfigurationPropertiesJsr303Validator.java:64)
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.<init>(ConfigurationPropertiesBinder.java:69)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.afterPropertiesSet(ConfigurationPropertiesBindingPostProcessor.java:78)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)
... 41 more
现在,理论上这是正确的 - 我在类上只有验证 api (2.0),没有实现。然而,这是故意的 - 有时我对实际执行验证不感兴趣,但我选择使用 API 进行注释以方便地记录合同。
有没有办法绕过这个检查?我理解其中的原因,但我认为强迫这样做是错误的。