0

I would like to be able to use a value within my list as the key to my map with spring boot properties. Is this possible?

I'm new to spring-boot and using @ConfigurationProperties. I've a properties class like below

@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

Is it possible to reference a list value as the key for another property within application.properties?

1 Answers1

0

Are you using the @PropertySource annotation to use the .properties file.

For example:

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

    }
Cisco
  • 20,972
  • 5
  • 38
  • 60
Maninder
  • 1,539
  • 1
  • 10
  • 12