Mybatis 中出现 org.apache.ibatis.type.TypeException: Could not resolve type alias异常

 

 

C:\JDK\jdk1_8.0.131\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\Idea2018\IntelliJ IDEA 2018.3.5\lib\idea_rt.jar=50933:D:\Idea2018\IntelliJ IDEA 2018.3.5\bin" -Dfile.encoding=UTF-8 -classpath "D:\Idea2018\IntelliJ IDEA 2018.3.5\lib\idea_rt.jar;D:\Idea2018\IntelliJ IDEA 2018.3.5\plugins\junit\lib\junit-rt.jar;D:\Idea2018\IntelliJ IDEA 2018.3.5\plugins\junit\lib\junit5-rt.jar;C:\JDK\jdk1_8.0.131\jre\lib\charsets.jar;C:\JDK\jdk1_8.0.131\jre\lib\deploy.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\access-bridge-64.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\cldrdata.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\dnsns.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\jaccess.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\jfxrt.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\localedata.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\nashorn.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\sunec.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\sunjce_provider.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\sunmscapi.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\sunpkcs11.jar;C:\JDK\jdk1_8.0.131\jre\lib\ext\zipfs.jar;C:\JDK\jdk1_8.0.131\jre\lib\javaws.jar;C:\JDK\jdk1_8.0.131\jre\lib\jce.jar;C:\JDK\jdk1_8.0.131\jre\lib\jfr.jar;C:\JDK\jdk1_8.0.131\jre\lib\jfxswt.jar;C:\JDK\jdk1_8.0.131\jre\lib\jsse.jar;C:\JDK\jdk1_8.0.131\jre\lib\management-agent.jar;C:\JDK\jdk1_8.0.131\jre\lib\plugin.jar;C:\JDK\jdk1_8.0.131\jre\lib\resources.jar;C:\JDK\jdk1_8.0.131\jre\lib\rt.jar;E:\WorkSpace\框架\Mybatis\Mybatis\target\test-classes;E:\WorkSpace\框架\Mybatis\Mybatis\target\classes;C:\Users\一枝叶\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\一枝叶\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\一枝叶\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar;C:\Users\一枝叶\.m2\repository\org\mybatis\mybatis\3.2.6\mybatis-3.2.6.jar;C:\Users\一枝叶\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 Test,getList
[DEBUG] 2019-04-25 09:15:09,830 org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
[DEBUG] 2019-04-25 09:15:09,846 org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2019-04-25 09:15:09,846 org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2019-04-25 09:15:09,846 org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2019-04-25 09:15:09,846 org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.

java.lang.ExceptionInInitializerError
	at Test.getList(Test.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in UserMapper.xml
### The error occurred while processing mapper_resultMap[getBill]
### 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 'getBill'.  Cause: java.lang.ClassNotFoundException: Cannot find class: getBill
	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 cn.einblatt.ssm.util.CreateSqlSession.<clinit>(CreateSqlSession.java:21)
	... 23 more
Caused by: 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 'getBill'.  Cause: java.lang.ClassNotFoundException: Cannot find class: getBill
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	... 25 more
Caused by: 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 'getBill'.  Cause: java.lang.ClassNotFoundException: Cannot find class: getBill
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
	... 27 more
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'getBill'.  Cause: java.lang.ClassNotFoundException: Cannot find class: getBill
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:103)
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:72)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
	... 30 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'getBill'.  Cause: java.lang.ClassNotFoundException: Cannot find class: getBill
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:117)
	at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:130)
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:101)
	... 34 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: getBill
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:190)
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
	at org.apache.ibatis.io.Resources.classForName(Resources.java:256)
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:113)
	... 36 more


Process finished with exit code -1

运行时报此错 

 

 原因:将resultMap写成了resultType,Type对应的是对象类,所以抛出ClassNotFoundException的异常,mybatis的结果是存放在resultMap中的

解决方法:将resultType改成resultMap即可

 

resultType属性和reusltMap的区别


restulyType:对应的是java对象中的属性,大小写不敏感,查询出来的列明和pojo中属性名一直才能映射成功;

resultMap:指的是定义好了的id的,是定义好的resyltType的引用,如果查询出来的列名和pojo中的属性名不一致,通过定义一个                      resultMap对列名和属性名之间做一个映射关系。

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值