Skip to content

Doc: ReloadableResourceBundleMessageSource's setUseCodeAsDefaultMessage causes the ValidationMessages.properties to not be found and used correctly [SPR-15986] #20536

Closed
@spring-projects-issues

Description

@spring-projects-issues

Happy opened SPR-15986 and commented

There are a few issues with using ```java
ReloadableResourceBundleMessageSource


1)Hibernate ValidationMessages.properties is not discovered 

When injecting a new ```java
ReloadableResourceBundleMessageSource
``` into 

```java 
  @Bean
  public SpringValidatorAdapter springValidatorAdapterFactory()
  {
    LocalValidatorFactoryBean springValidatorAdapter = new LocalValidatorFactoryBean();
    springValidatorAdapter.setValidationMessageSource(messageSource);// <-- here
    return springValidatorAdapter;
  }

then the messages from teh hibernate ValidationMessages.properties are picked and displayed accurately.

When I use ```java
ReloadableResourceBundleMessageSource

```java 
   @Bean
  public MessageSource messageSource()
  {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames(MESSAGE_SOURCE_BASE_NAMES); //path to i18n/messages
    messageSource.setUseCodeAsDefaultMessage(true);
    messageSource.setDefaultEncoding(UTF8_ENCODING);
    messageSource.setFallbackToSystemLocale(false);
    messageSource.setCacheSeconds((int) TimeUnit.HOURS.toSeconds(1));
    return messageSource;
  }

the ValidationMessages.properties file is never scanned.

However, when I set the following to false, comment from the above

// messageSource.setUseCodeAsDefaultMessage(true);

The ValidationMessages.properties from hibernate is correctly loaded.

I wouldn't have thought UseCodeAsDefaultMessage would cause this problem. But it does.
I have also faced problems as discussed in https://stackoverflow.com/q/23448360/1083581 and commenting out useCodeAsDefaultMessage has fixed errors. It however exposes my app to show errors when message codes aren't found.
I am using 4.3.4-RELEASE of spring-context.


Affects: 4.3.5

Referenced from: commits 37ab8a7, ce94026

Backported to: 4.3.15

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions