I am using the Spring Boot 2.1.1.RELEASE where in I am not able to access the configured Message Source.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/>
</parent>
@SpringBootApplication
public class RestfulWebservicesApplication {
//......... some code
//......... some code
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver resolver = new SessionLocaleResolver();
resolver.setDefaultLocale(Locale.US);
return resolver;
}
@Bean
public MessageSource resourceBundleMessageSource() {
ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource ();
resourceBundleMessageSource.setBasename("classpath:messages");
return resourceBundleMessageSource;
}
Above approach is from another SO question
Below is the my restcontroller class method:
@GetMapping("/hello-world-I18N")
public String helloWorldI18N(@RequestHeader(name="Accept-Language",required = false) Locale locale) {
return messageSource.getMessage("good.morning.message",null,locale);
}
In Debug log auto configuration did not match.
MessageSourceAutoConfiguration: Did not match: - ResourceBundle did not find bundle with basename messages (MessageSourceAutoConfiguration.ResourceBundleCondition)
I did tried the other way where in the configuration have been detected but the error was same as highlighted.
@Bean
public MessageSource resourceBundleMessageSource() {
ReloadableResourceBundleMessageSource resourceBundleMessageSource = new ReloadableResourceBundleMessageSource ();
resourceBundleMessageSource.setBasename("messages");
return resourceBundleMessageSource;
}
MessageSourceAutoConfiguration:
Did not match:
- @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: current) found beans of type 'org.springframework.context.MessageSource' resourceBundleMessageSource (OnBeanCondition)
Matched:
- ResourceBundle found bundle URL [file:/C:/Users/gaura/IdeaProjects/restful-webservices/target/classes/messages.properties] (MessageSourceAutoConfiguration.ResourceBundleCondition)
content of messages.properties: good.morning.message=Good Morning
Does it is the issue with current Spring Boot 2.1.1.RELEASE just like the other version???