Recently while I was working on some Spring based Web Application, I encountered an Error Message No message found under code '<<XXX>>' for locale '<<YYY>>'., when I was trying to fetch the message code Using MessageSource implementation which is autowired in a service class.
I first checked the MessageSource bean definition in the @Configuration annotated java class is good or not. The underlying implementation class as used in the bean definition ResourceBundleMessageSource. So I checked its parameters like baseName is having proper path to the resource or not,defaultEncoding is UTF-8 (As I have been using UTF-8 for encoding) or not etc and I found them perfectly good. Then I checked whether the resource (i.e. .properties file) the MessageSource is pointing to, is at per with the baseName and in classpath, and surprisingly I found it also perfectly good.
Next, I thought of using ReloadableResourceBundleMessageSource with appropiate parameter set and this effort of mine is also vain and this implementation too could not made the code error-free. Even for both the implementation classes I have appended classpath: with value in the parameter baseName but nothing is turning to be effective enough for me.
I was really scratching my head, as I could not figure out where I was going wrong. Since you all could understand that I have really tried out each and every possible course of action.
Next, I thought of looking at the debug log file, which logs the details of all Spring configured beans of the application context, there I found that my bean is getting overwritten by another bean of same name, as a result of which I was getting the above mentioned error. Actually my Web Application is has got its own MessageResource bean configured, and this application is dependent on another module (which is present as jar in the Web Application's classpath), which has got its MessageResource bean configured with the same name as that of Web Application's. Now when I am trying to fetch the messages for the dependent module I was getting the above error as the MessageResource bean confugured in the dependent module's configuration is being overwritten with that of Web Application's.
So, we should always configure our logging properly and always be very careful while configuring beans, so that they should not have same name.
I first checked the MessageSource bean definition in the @Configuration annotated java class is good or not. The underlying implementation class as used in the bean definition ResourceBundleMessageSource. So I checked its parameters like baseName is having proper path to the resource or not,defaultEncoding is UTF-8 (As I have been using UTF-8 for encoding) or not etc and I found them perfectly good. Then I checked whether the resource (i.e. .properties file) the MessageSource is pointing to, is at per with the baseName and in classpath, and surprisingly I found it also perfectly good.
Next, I thought of using ReloadableResourceBundleMessageSource with appropiate parameter set and this effort of mine is also vain and this implementation too could not made the code error-free. Even for both the implementation classes I have appended classpath: with value in the parameter baseName but nothing is turning to be effective enough for me.
I was really scratching my head, as I could not figure out where I was going wrong. Since you all could understand that I have really tried out each and every possible course of action.
Next, I thought of looking at the debug log file, which logs the details of all Spring configured beans of the application context, there I found that my bean is getting overwritten by another bean of same name, as a result of which I was getting the above mentioned error. Actually my Web Application is has got its own MessageResource bean configured, and this application is dependent on another module (which is present as jar in the Web Application's classpath), which has got its MessageResource bean configured with the same name as that of Web Application's. Now when I am trying to fetch the messages for the dependent module I was getting the above error as the MessageResource bean confugured in the dependent module's configuration is being overwritten with that of Web Application's.
So, we should always configure our logging properly and always be very careful while configuring beans, so that they should not have same name.