I have a properties file like for example *.properties key1 = value1 key2 = value2
Is there way to store all the key value pairs in a hash map?
I have a properties file like for example *.properties key1 = value1 key2 = value2
Is there way to store all the key value pairs in a hash map?
If the question relates to the Spring framework, then you can create Configuration Beans based on a *.properties or *.yml files.
Example MyAppProperties.java
@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
@Configuration
@ConfigurationProperties(prefix = "props")
public class MyAppProperties {
Map<String, String> map = new HashMap<>();
}
And your properties that start with props.map.* will be available through this Configuration Bean, which can be obtained from the application context.
props.map.key1=value1
props.map.key2=value2
For more information, see the documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.java-bean-binding