diff --git a/microsphere-i18n-spring/src/main/java/io/microsphere/i18n/spring/beans/factory/config/I18nBeanPostProcessor.java b/microsphere-i18n-spring/src/main/java/io/microsphere/i18n/spring/beans/factory/config/I18nBeanPostProcessor.java index fa18e16..5d4f461 100644 --- a/microsphere-i18n-spring/src/main/java/io/microsphere/i18n/spring/beans/factory/config/I18nBeanPostProcessor.java +++ b/microsphere-i18n-spring/src/main/java/io/microsphere/i18n/spring/beans/factory/config/I18nBeanPostProcessor.java @@ -9,6 +9,7 @@ import org.springframework.context.MessageSource; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; +import static io.microsphere.spring.util.BeanUtils.getOptionalBean; import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static org.springframework.aop.support.AopUtils.getTargetClass; @@ -46,10 +47,14 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro Class beanType = getTargetClass(bean); if (LOCAL_VALIDATOR_FACTORY_BEAN_CLASS.equals(beanType)) { - MessageSourceAdapter messageSourceAdapter = context.getBean(MessageSourceAdapter.class); - LocalValidatorFactoryBean localValidatorFactoryBean = (LocalValidatorFactoryBean) bean; - localValidatorFactoryBean.setValidationMessageSource(messageSourceAdapter); - logger.debug("LocalValidatorFactoryBean[name : '{}'] is associated with MessageSource : {}", beanName, messageSourceAdapter); + MessageSourceAdapter messageSourceAdapter = getOptionalBean(this.context, MessageSourceAdapter.class); + if (messageSourceAdapter == null) { + logger.warn("No MessageSourceAdapter BeanDefinition was found!"); + }else{ + LocalValidatorFactoryBean localValidatorFactoryBean = (LocalValidatorFactoryBean) bean; + localValidatorFactoryBean.setValidationMessageSource(messageSourceAdapter); + logger.debug("LocalValidatorFactoryBean[name : '{}'] is associated with MessageSource : {}", beanName, messageSourceAdapter); + } } return bean;