Mybatis关于The error may exist in *mapper.xml的一种报错,读取不到实体类,别名问题
最近在学习mybatis,错误: 编译器找不到*mapper.xml,更准确的说是找不到实体类,挺低级的错误。报错信息如下:D:\Java\jdk1.8.0_171\bin\java.exejava.lang.ExceptionInInitializerErrorat TestSmbms.before(TestSmbms.java:19)at sun.reflect.NativeM...
·
最近在学习mybatis,错误: 编译器找不到*mapper.xml,更准确的说是找不到实体类,挺低级的错误。报错信息如下:
D:\Java\jdk1.8.0_171\bin\java.exe
java.lang.ExceptionInInitializerError
at TestSmbms.before(TestSmbms.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
### Error building SqlSession.
### The error may exist in com/hm/mapper/UserMapsper.xml
### **Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper 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:
Process finished with exit code -1
实体类在bean的目录下,报错User没读取到
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="config/database.properties"></properties>
<!--设置别名 如果未设置别名报错-->
<typeAliases>
<package name="com.hm.bean"></package>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/hm/mapper/UserMapper.xml"/>
</mappers>
</configuration>
感觉今天又水一贴,总结下我用的是批量设置别名
package为某个包下的所有类起别名,name为包名,当前包以下面的每一个子包里的类都起一个默认别名
更多推荐
已为社区贡献2条内容
所有评论(0)