一: import org.apache.ibatis.io.Resources; InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
二: private void scanPackage(String basePackage) { //扫描编译好的类路径下所有的类 URL url = this.getClass().getClassLoader().getResource("/" + replaceTo(basePackage)); String fileStr = url.getFile(); File file = new File(fileStr); //拿到所有类com.enjoy下的james文件夹 String[] filesStr = file.list(); for (String path : filesStr) { File filePath = new File(fileStr + path);//扫描com.enjoy.james下的所有class类 //递归调用扫描,如果是路径,继续扫描 if (filePath.isDirectory()) { // com.enjoy.james scanPackage(basePackage + "." + path); } else { classNames.add(basePackage + "." + filePath.getName());//如果是class文件则加入List集合(待生成bean) } } }