Home > Software engineering >  Map<String, User> in yaml file for @ConfirgurationProperties in java?
Map<String, User> in yaml file for @ConfirgurationProperties in java?

Time:09-16

Hello I have a configuration class in a spring boot project that looks something like this .

  @ConfigurationProperties(config.value) 
     public class ApplicationProperties{
              Map<String, User> userProperties;
        }
       
     public class User{
              String userName;
              String userCity;
      }

How do I give value for userProperties in my application.yaml file ?

CodePudding user response:

Given your example, the corresponding configuration properties for two different users in application.yml would look as follows:

userProperties:
  user1:
    userName: jane
    userCity: New York
  user2:
    userName: john
    userCity: Lisbon
  • Related