国际化之MessageSourceAware和MessageSourceAccessor

先看接口MessageSourceAware
该接口的注释中

Note that the MessageSource can usually also be passed on as bean reference (to arbitrary bean properties or constructor arguments), because it is defined as bean with name "messageSource" in the application context.

大概意思是如果上下文中有名为messageSource的bean,那么会自动注入这个bean。
因此MessageSourceAware中肯定有一个方法void setMessageSource(MessageSource messageSource);

因为建议在要进行国际化操作的 ,让它实现接口MessageSourceAware
public class CgodoSimpleUrlAuthenticationFailureHandler extends
SimpleUrlAuthenticationFailureHandler implements MessageSourceAware {
protected MessageSourceAccessor messages;

@Override
public void setMessageSource(MessageSource messageSource) {
messages = new MessageSourceAccessor(messageSource);
}
然后通过如上方式来实现一个MessageSourceAccessor

你可能感兴趣的:(message)