Spring Webflow: How to establish my own ReloadableResourceBundleMessageSource for a flow

69 Views Asked by At

Spring Webflow 2.5.1.

I have my own implementation of ReloadableResourceBundleMessageSource. I can successfully establish it in Spring MVC via:


    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource source = new AwareReloadableResourceBundleMessageSource();
        source.setCacheSeconds(cacheSeconds);
        source.setBasename("WEB-INF/i18n/messages");
        source.setUseCodeAsDefaultMessage(true);
        source.setDefaultEncoding("UTF-8");
        return source;
    }

My application uses both Spring MVC and Webflow.

I would like to have instances of the same AwareReloadableResourceBundleMessageSource in place for the individual per-flow messages.properties files.

I have tried:

@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {
  ...


    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource ms = new AwareReloadableResourceBundleMessageSource();
        ms.setBasename("messages");

        System.out.println("MESSAGE SOURCE AwareReloadableResourceBundleMessageSource");
        return ms;
    }
}

But the messageSource() method is not called.

I have seen: https://stackoverflow.com/a/8126164

Any pointers/techniques/code snipppets very gratefully accepted.

1

There are 1 best solutions below

1
sree On

Try the following:

  1. Configure messageSource() within a ValidatorFactory bean, AND

  2. Configure the ValidatorFactory bean within FlowBuilderServices

    @Bean public FlowBuilderServices flowBuilderServices() { return getFlowBuilderServicesBuilder() .setValidator(getValidator()) .build(); }

    @Bean public LocalValidatorFactoryBean getValidator() { LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean(); bean.setValidationMessageSource(messageSource()); return bean; }