mybatis报这个错的原因是没有在mybatis-config.xml中注册
<mappers>
<mapper resource="org/mybatis/example/BlogMapper.xml"/>
</mappers>
记得加这个
加上之后再运行报这个错:java.lang.ExceptionInInitializerError
原因:target中不会自动将xml文件编译生成class文件保存进去,所以资源导出失败。
可以看到target里没有xml文件
要在pom.xml中配置如下代码
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>