0

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.

1 Answer 1

2

Try using MessageSource instead of ReloadableResourceBundleMessageSource

@Autowired
private MessageSource messageSource;
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. I assume that ReloadableResourceBundleMessageSource is a proxy or abstract class?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.