Spring boot 3.2.1 属性绑定

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

我依赖于具有

的库
@ConfigurationProperties(prefix = "foo.web.auth")
@Getter
public class WebAuthConfigurationProperties {
  private final String endpoint;
  private final String loadBalancingPolicy;
  private final KeyConfiguration key;
  private final boolean tracingEnabled;
  private final Token token;
  private final RetryPolicies retryPolicies;
  ...
}
@AutoConfiguration(after = WebMvcAutoConfiguration.class)
@ConditionalOnWebApplication
public class WebAuthAutoConfiguration {

  @Configuration(proxyBeanMethods = false)
  @Import({AuthConfiguration.class})
  @ConditionalOnProperty(value = "foo.web.auth.enabled", havingValue = "true")
  protected static class WebAuthEnabledAutoConfiguration {}

  @Configuration(proxyBeanMethods = false)
  @Import({AuthDisabledConfiguration.class})
  @ConditionalOnProperty(
      value = "foo.web.auth.enabled",
      havingValue = "false",
      matchIfMissing = true)
  protected static class WebAuthDisabledAutoConfiguration {}
}
foo:
  web:
# It should be turned on after the new Spring Boot 3.2.1 becomes available.
# Issue: https://github.com/spring-projects/spring-boot/issues/38556
    auth:
      enabled: true
      endpoint: https://auth-headless.auth:8443
      token:
        fakeAuth: true

升级到Spring boot 3.2.1后 我明白了

上下文初始化期间遇到异常 - 取消 刷新尝试: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: 使用名称创建 bean 时出错 'foo.web.auth-com.tink.springframework.boot.autoconfigure.web.auth.WebAuthConfigurationProperties': 无法将属性绑定到“WebAuthConfigurationProperties”: 前缀=foo.web.auth,ignoreInvalidFields=false, 忽略未知字段=true

看起来像

@ConditionalOnProperty(value = "foo.web.auth.enabled", havingValue = "true")
不行。我认为这与 spring 问题 有关,但是在迁移到 Spring boot 3.2.1 和 Spring Framework 6.1.2 后,我仍然遇到相同的异常。

我希望属性绑定将像以前一样在 Spring boot 3.1.5 中工作

spring-boot
1个回答
0
投票

我认为你只需要添加设置器:@Setter

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