是否可以将spring boot @Value与javax.validation.constraints结合使用?

问题描述 投票:2回答:1

我想验证application.properties中的值。我使用@Value注入,并使用@NotBlank验证用@Configuration注释的类中的方法参数。

createSslContext(
            @Value("#{systemProperties['javax.net.ssl.trustStore']}") 
            @NotBlank(message = "Truststore is needed") 
            String path)

我已包含hibernate-validatorhibernate-validator-annotation-processor属性。使用Spring 2.2.0.RELEASE。

这不起作用。该值已注入,但未经验证。我想念什么?

我想验证application.properties中的值。我使用@Value注入,并使用@NotBlank验证用@Configuration注释的类中的方法参数。 createSslContext(...

java spring-boot jsr305
1个回答
0
投票

@Validated添加到您的配置类。

© www.soinside.com 2019 - 2024. All rights reserved.