I am using Spring Boot
and Java
and my application.properties
file looks like this right now:
germany.berlin.zipcode.10245=Friedrichshain
germany.berlin.zipcode.14193=Charlottenburg
germany.berlin.zipcode.10247=Neukolln
I am using @ConfigurationProperties
to extract the values assigned in the properties in my code. More specifically I want to be able to give the zipcode number(e.g. 10245) in a method and it should return the place (Friedrichshain in that case). What I have tried so far:
Properties Config class
@EnableConfigurationProperties(AddressConfig.class)
public class PropertiesConfig {
}
AddressConfig class
@Setter
@Getter
@Component
@ConfigurationProperties(prefix = "germany.berlin")
public class AddressConfig {
private Map<Integer, String> zipCode;
public String getAreaForzipCode(int code) {
return zipCode.get(code);
}
}
But when I do:
getAreaForzipCode(10245)
I get a java.lang.NullPointerException: null
Does anyone know whats the proper way to do this? Thanks in advance