【问题标题】:Spring-boot: Referencing a list value within another propertySpring-boot:引用另一个属性中的列表值
【发布时间】:2022-01-13 15:16:21
【问题描述】:

我希望能够使用我的列表中的一个值作为我的带有 Spring Boot 属性的地图的键。这可能吗?

我是 spring-boot 和使用 @ConfigurationProperties 的新手。我有一个如下所示的属性类

@Data
@ConfigurationProperties(prefix = "test")
public class TestProperties{
   private List<String> tableNames;
   private Map<String, String> fieldNames;
}

application.properties

test.table-names[0]=car.information.table

#I would like to do something like this but I get the following error:
#Can't use '[..]' navigation for property 'test.field-names.$(test.table-names' of type java.lang.String
test.field-names.${test.table-names[0]}=Id,Model,Make,Year

#I've a workaround like this for now:
test.field-names.car\.information\.table=Id,Model,Make,Year

是否可以引用列表值作为 application.properties 中另一个属性的键?

【问题讨论】:

    标签: spring-boot properties configurationproperties


    【解决方案1】:

    你是在使用@PropertySource注解来使用.properties文件吗?

    例如:

        @Configuration
        @ComponentScan(basePackages = "io.reactivestax")
        @PropertySource("database.properties")
        public class AppConfig {
    
        }
    

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 2015-10-23
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多