Spring framework: no messages found by locale code

This is my MessageResource ad.

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Auto-detect controllers in this package -->
    <context:component-scan base-package="levelup.world.web" />

    <!-- Prepend /WEB-INF/jsp/ and append .jsp to the view name -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- Access resource bundles with the specified basename -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
        p:basename="/WEB-INF/messages/" />

</beans>

When starting the application, this error is displayed

No message found under code 'country.plural' for locale 'fil_PH'

now inside my message folder inside web-inf, I have the following message properties

messages_en.properties
messages_fr.properties
messages.properties

What am I missing here?

+12
source share
4 answers

In general, such a problem does not arise due to linguistic non-existence, but because it is MessageBundleconfigured incorrectly. In your case, you seem to need to remove the "/" in your base name.

<bean id="messageSource"
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
     p:basename="/WEB-INF/messages" />

Why is this so:

messages.properties messages_en.properties, messages. WEB-INF, basename /WEB-INF/messages, /path/to/bundle/bundlename. /WEB-INF/messages messages.properties, /WEB-INF/messages/messages.

+23

spring - :

@Bean
public MessageSource messageSource() {
     ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
     messageSource.setBasename("/WEB-INF/classes/messages");
     return messageSource;
}
+10

Spring boot application.properties

# INTERNATIONALIZATION 
spring.messages.basename=i18n/messages
spring.messages.encoding=UTF-8
+1

Bean:

@Bean(name="messageSource")
public ResourceBundleMessageSource bundleMessageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
0

All Articles