NoSuchMessageException - Spring ReloadableResourceBundleMessageSource vs ResourceBundleMessageSource

I have defined the following Spring bean:

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

      

Controller:

@Controller
public class EuserController {

    @Inject
    MessageSource messageSource;

    @RequestMapping(value="/euser/{empId}", method=RequestMethod.DELETE)
    public @ResponseBody String deleteEeuserById(@PathVariable(value="empId") Integer id) {
        return messageSource.getMessage("deleteEuser.success", null, LocaleContextHolder.getLocale());
    }
}

      

And it works great. But when I try to replace:

org.springframework.context.support.ReloadableResourceBundleMessageSource

      

from:

org.springframework.context.support.ResourceBundleMessageSource

      

and I get a org.springframework.context.NoSuchMessageException

.

What happens when used org.springframework.context.support.ResourceBundleMessageSource

instead?

+3


source to share


1 answer


ReloadableResourceBundleMessageSource

is an alternative ResourceBundleMessageSource

that is capable of updating messages while the application is running. It's also more powerful since you're not limited to packages on the classpath, but you can also download files from elsewhere.

When used, ResourceBundleMessageSource

you need to restart the application when you make changes, as it ResourceBundleMessageSource

does not reload your packages when they change. The prefix classpath:

also needs to be removed. This has to do with how the two classes work:



+9


source







All Articles