System.out.println("class.getResource()输出^_^");
// file:/.../target/classes/.../mybatis-config.xml
System.out.println(TestDemo.class.getResource("mybatis-config.xml"));
// file:/.../target/classes/
System.out.println(TestDemo.class.getResource("/"));
// file:/.../target/classes/../mybatis
// 当前类所在路径
System.out.println(TestDemo.class.getResource(""));
System.out.println("----------------------------------");
System.out.println("getClassLoader().getResource()输出^_^");
// 找不到输出null
System.out.println(TestDemo.class.getClassLoader().getResource("mybatis-config.xml"));
// 找不到输出null
System.out.println(TestDemo.class.getClassLoader().getResource("/"));
// file:/../target/classes/
System.out.println(TestDemo.class.getClassLoader().getResource(""));
System.out.println("----------------------------------");
System.out.println("其他形式调用^_^");
// file:/.../target/classes/
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
// 找不到输出null
System.out.println(Thread.currentThread().getContextClassLoader().getResource("mybatis-config.xml"));
// file:/.../target/classes/
System.out.println(ClassLoader.getSystemResource(""));
TestDemo.class.getResource("")
当前类所在路径
TestDemo.class.getResource("/")
编译路径根目录
class.getClassLoader().getResource("")
编译路径根目录