Skip to content

Commit 4e8409c

Browse files
authored
Merge branch 'microsphere-projects:main' into addTest
2 parents 7a11ea5 + 9a3c482 commit 4e8409c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

microsphere-i18n-spring/src/main/java/io/microsphere/i18n/spring/beans/factory/config/I18nBeanPostProcessor.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.context.MessageSource;
1010
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
1111

12+
import static io.microsphere.spring.util.BeanUtils.getOptionalBean;
1213
import static io.microsphere.util.ClassLoaderUtils.resolveClass;
1314
import static org.springframework.aop.support.AopUtils.getTargetClass;
1415

@@ -46,10 +47,14 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
4647

4748
Class<?> beanType = getTargetClass(bean);
4849
if (LOCAL_VALIDATOR_FACTORY_BEAN_CLASS.equals(beanType)) {
49-
MessageSourceAdapter messageSourceAdapter = context.getBean(MessageSourceAdapter.class);
50-
LocalValidatorFactoryBean localValidatorFactoryBean = (LocalValidatorFactoryBean) bean;
51-
localValidatorFactoryBean.setValidationMessageSource(messageSourceAdapter);
52-
logger.debug("LocalValidatorFactoryBean[name : '{}'] is associated with MessageSource : {}", beanName, messageSourceAdapter);
50+
MessageSourceAdapter messageSourceAdapter = getOptionalBean(this.context, MessageSourceAdapter.class);
51+
if (messageSourceAdapter == null) {
52+
logger.warn("No MessageSourceAdapter BeanDefinition was found!");
53+
}else{
54+
LocalValidatorFactoryBean localValidatorFactoryBean = (LocalValidatorFactoryBean) bean;
55+
localValidatorFactoryBean.setValidationMessageSource(messageSourceAdapter);
56+
logger.debug("LocalValidatorFactoryBean[name : '{}'] is associated with MessageSource : {}", beanName, messageSourceAdapter);
57+
}
5358
}
5459

5560
return bean;

0 commit comments

Comments
 (0)