I want to send a localized email from my controller.
My localization is configured and working fine in my Thymeleaf tiles.
My configuration is as follows:
...
<!-- i18n -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:messages</value>
<value>classpath:cpcscorereport</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="zh_CN" />
</bean>
...
</beans>
So theoretically I autowire message source into the controller as follows:
@Autowired
private ReloadableResourceBundleMessageSource messageSource;
Then access the messages as follows:
String message = messageSource.getMessage("report.title", null, LocaleContextHolder.getLocale());
SSm.getLogger().debug("localized message: "+message);
BUt I get the following exception at autowire
23-Feb-2017 18:19:06.969 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet AssessmentDelivery org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.context.support.ReloadableResourceBundleMessageSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Why is it not picking up the autowired bean in the controller?
Any suggestions would be much appreciated.