I have a spring boot application where I want to externalize the messages. I am categorizing these messages into errors, info, and success. Thus I'm creating a nested folder structure as below:
And, I'm trying to access this from the service in the following manner:
Locale locale = new Locale("en");
ResourceBundle errors = ResourceBundle.getBundle("errors", locale);
System.out.println(errors.getString("E000"));
This gives me the following exception:
java.util.MissingResourceException: Can't find bundle for base name errors, locale en
However, if I keep the properties file outside the folders as below, it works fine:
So,
Use below will work: as resources is your class path so you need to pass messages also..if you will move out errors file from messages to classpath so it works as by default classpath is resources..
ResourceBundle errors = ResourceBundle.getBundle("messages/errors/errors", locale);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With