Maven异常
HTTP Status 500 – Internal Server Error
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
...
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/baizhi/dao/DeptDaoMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/baizhi/dao/DeptDaoMapper.xml
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
at com.baizhi.util.MybatisUtil.<clinit>(MybatisUtil.java:20)
at com.baizhi.service.UserServiceImp.login(UserServiceImp.java:13)
at com.baizhi.action.UserAction.login(UserAction.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
...
原因:注册 mapper 的路径并没有问题,却一直显示找不到 mapper 文件,猜测是 build 的时候没有将 mapper.xml 编译进去。
应该是maven规定mapper.xml一类的文件只能放在src/main/resources文件夹下,否则读取不到。
解决办法1:将mapper.xml文件都放在src/main/resources文件夹中,具体操作:
1、在src/main/resouces目录下创建com/xxx/mapper文件夹
2、将所有mapper文件放在该文件夹下
3、在mybaits-config.xml中正常注册mapper文件
解决办法2:若不想新建mapper文件夹,则在 pom.xml 的 build 中添加以下代码:
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>