String path = System.getProperty("user.dir") + "\\src\\main\\resources\\mybatis-config.xml";

运行调试:

导入配置文件

即此不能用于java web,只能用作本地执行文件。

那java web如何导入配置文件?

通过执行发现,src/main/resources下面的xml与properties文件,在编译后会在XXX\target\boms-v2.1.1\WEB-INF\classes,问题演变为如何导入web-inf/class下的配置文件

String path = Thread.currentThread().getContextClassLoader()
        .getResource("pwdmybatis-config.xml").getPath();

转载于:https://my.oschina.net/u/560971/blog/1555023

相关文章: