fix: 新增字典处理

This commit is contained in:
wangyu 2021-03-21 23:53:26 +08:00
parent 2a39d64ff3
commit ee4d57a58f

View File

@ -13,7 +13,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.reflections.Reflections;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
@ -33,7 +32,7 @@ import java.util.stream.Stream;
* 用于反向注册默认值
*/
@RequiredArgsConstructor
public class DictionaryProcessor implements InitializingBean, ImportBeanDefinitionRegistrar {
public class DictionaryProcessor implements ImportBeanDefinitionRegistrar {
private final DictionaryService dictionaryService;
@ -42,8 +41,7 @@ public class DictionaryProcessor implements InitializingBean, ImportBeanDefiniti
/**
* spring加载完成后尝试注入值
*/
@Override
public void afterPropertiesSet() {
public void initialize() {
Assert.notNull(basePackages, "未指定明确的字典扫描路径!");
Reflections reflections = new Reflections(Stream.of(basePackages).collect(Collectors.toSet()));
Set<Field> fields = reflections.getFieldsAnnotatedWith(DictValue.class);
@ -98,5 +96,6 @@ public class DictionaryProcessor implements InitializingBean, ImportBeanDefiniti
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
Map<String, Object> attrs = metadata.getAnnotationAttributes(EnableDictProcess.class.getCanonicalName(), true);
this.basePackages = (String[]) MapUtils.getObject(attrs, "basePackages");
this.initialize();
}
}