getResourceAsStream、getResource

一:
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)
      }
   }
}
相关文章
相关标签/搜索