Я пытаюсь получить карту с {"host1": DatabaseConfigurationProperty("abcd", "mytable", "user")}
, однако мой код ниже генерирует только пустую карту.
application.yml:
database:
host1:
hostname: abcd
name: mytable
username: user
DatabaseConfigurationProperty.java:
@Configuration
@ConfigurationProperties("database")
@EnableConfigurationProperties
@Component
public class DatabaseConfigurationProperty {
Map<String, DatabaseConfiguration> database = new HashMap<>();
public Map<String, DatabaseConfiguration> getDatabase() {
return database;
}
public void setDatabase(Map<String, DatabaseConfiguration> database) {
this.database = database;
}
}
DatabaseConfiguration.java:
public class DatabaseConfiguration {
String host;
String name;
String username;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
MainConfig.java:
@Configuration
public class MainConfig {
@Autowired
private DatabaseConfigurationProperty databaseConfigurationProperty;
}
databaseConfigurationProperty.getDatabase () возвращается в виде пустой карты.