Skip to content

Commit

Permalink
Update I18nBeanPostProcessor.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed May 13, 2024
1 parent 4ca1136 commit 9a3c482
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9a3c482

Please sign in to comment.