// 资源列表 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); // 遍历资源 Resource[] resources = resolver.getResources("classpath: com/hello/app/component/*.class"); List<Class<?>> classes = new ArrayList<>(); for (Resource resource : resources) { String className = packageName + "." + resource.getFilename().replace(".class", ""); Class<?> clazz = Class.forName(className); // 过滤出非class文件 if(clazz.isInterface()){ continue; } classes.add(clazz); } return classes;
SpringBoot环境读取某目录下的类,可作为静态方法使用
最新推荐文章于 2024-09-07 13:34:01 发布