今天使用Mybatis时发现许多问题。 org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/atlin/dao/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/atlin/dao/UserMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'User'. Cause: java.lang.ClassNotFoundException: Cannot find class: User
如果出这个错误,大概率是 这个resultType没有使用具体位置
java.io.IOException: Could not find resource UserMapper.xml
如果报这个错误,有很多情况,一种是maven的优先级配置问题,如果出现这个问题,那只需要在pom.xml中加入以下代码
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes >
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
可以通过使用 maven install 看看目录target下是否有UserMapper.xml,如果有,说明配置成功.一般以上方法即可。 当然,我在配置这个的时候也成功了,我找了很久才发现自己代码写错了 其中resource写成了dao下的xml。 记住 需要用斜杠而不是.
|