获取 一个 一个包名下面的 所有类

spring 提供了实现

 

 

		 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
         MetadataReaderFactory metaReader = new CachingMetadataReaderFactory();
         Resource[] resources = resolver.getResources("classpath*:com/chuanyi/ecard/bean/in/*.class");
         ClassLoader loader = ClassLoader.getSystemClassLoader();
         for (Resource resource : resources) {
             MetadataReader reader = metaReader.getMetadataReader(resource);
             String className = reader.getClassMetadata().getClassName();
             Class<?> clazz = loader.loadClass(className);
             classList.add(clazz);
             System.out.println( clazz );
         }

  

posted on 2020-07-08 10:18  zhangyukun  阅读(461)  评论(0编辑  收藏  举报

导航