|
3 | 3 | import lombok.Getter;
|
4 | 4 | import lombok.Setter;
|
5 | 5 | import lombok.SneakyThrows;
|
| 6 | +import lombok.extern.slf4j.Slf4j; |
6 | 7 | import org.hswebframework.web.dict.EnumDict;
|
7 | 8 | import org.springframework.boot.context.properties.ConfigurationProperties;
|
8 | 9 | import org.springframework.core.io.Resource;
|
|
21 | 22 | @ConfigurationProperties(prefix = "hsweb.dict")
|
22 | 23 | @Getter
|
23 | 24 | @Setter
|
| 25 | +@Slf4j |
24 | 26 | public class DictionaryProperties {
|
25 | 27 |
|
26 |
| - private Set<String> enumPackages=new HashSet<>(); |
| 28 | + private Set<String> enumPackages = new HashSet<>(); |
27 | 29 |
|
28 | 30 | @SneakyThrows
|
29 |
| - public List<Class> doScanEnum(){ |
| 31 | + public List<Class> doScanEnum() { |
30 | 32 | Set<String> packages = new HashSet<>(enumPackages);
|
31 | 33 | packages.add("org.hswebframework.web");
|
32 | 34 | CachingMetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory();
|
33 | 35 | ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
|
34 | 36 | List<Class> classes = new ArrayList<>();
|
35 | 37 | for (String enumPackage : packages) {
|
36 |
| - String path = "classpath*:"+ ClassUtils.convertClassNameToResourcePath(enumPackage)+"/**/*.class"; |
| 38 | + String path = "classpath*:" + ClassUtils.convertClassNameToResourcePath(enumPackage) + "/**/*.class"; |
37 | 39 | Resource[] resources = resourcePatternResolver.getResources(path);
|
38 | 40 | for (Resource resource : resources) {
|
39 |
| - MetadataReader reader = metadataReaderFactory.getMetadataReader(resource); |
40 |
| - Class clazz=Class.forName(reader.getClassMetadata().getClassName()); |
41 |
| - if(clazz.isEnum()&& EnumDict.class.isAssignableFrom(clazz)){ |
42 |
| - classes.add(clazz); |
| 41 | + try { |
| 42 | + MetadataReader reader = metadataReaderFactory.getMetadataReader(resource); |
| 43 | + String name = reader.getClassMetadata().getClassName(); |
| 44 | + Class clazz = Class.forName(name); |
| 45 | + if (clazz.isEnum() && EnumDict.class.isAssignableFrom(clazz)) { |
| 46 | + classes.add(clazz); |
| 47 | + } |
| 48 | + } catch (Throwable e) { |
| 49 | + |
43 | 50 | }
|
44 | 51 | }
|
45 | 52 | }
|
|
0 commit comments