Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve spring message code using messageSource

I am trying to hook up a messageSource in spring to use for my application. Its not working, gives this error:

org.springframework.context.NoSuchMessageException: No message found under code 'validation_required' for locale 'en'.

my applicationContext.xml contains this def for messageSource:

   <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:messages</value>
            </list>
        </property>
    </bean>

my messages properties file lives in:

/WEB-INF/classes/messages/messages_en_US.properties

Finally, the call i made that generates the error is:

String message = messageSource.getMessage("validation_required", null, Locale.ENGLISH);

Can anyone help me at this hour?

like image 793
mkoryak Avatar asked Dec 17 '22 18:12

mkoryak


2 Answers

It seems like your path is not correct. since you have your bundle under /WEB-INF/classes/messages/messages_en_US.properties, your basename setting should look like: classpath:messages/messages (basename in this case means path and properties file prefix).

like image 90
Costi Ciudatu Avatar answered Dec 28 '22 05:12

Costi Ciudatu


The problem is with the way you have defined the resource bundle and the locale you are specifying (They doesn't match with the resource bundle's search order. Either rename your bundle to "messages_en.properties" or invoke the "getMessage(...)" with new Locale("en","US"). I prefer the first option.

like image 44
Aravind Yarram Avatar answered Dec 28 '22 06:12

Aravind Yarram