元素类型为 “resultMap“ 的内容必须匹配 “(constructor?,id*,result*,association*,collection*,discriminator?)“

一、问题

新搭建的springboot项目,在项目启动的时候报错

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testImpl': Unsatisfied dependency expressed through field 'ciclaimplatformdwService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testImpl': Unsatisfied dependency expressed through field 'testDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ciclaimplatformdwDao' defined in file [E:\test\target\classes\ins\claim\business\middle\dao\testwDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\test\target\classes\mapper\base\middle\test02Dao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 14; 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminator?)"。
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at ins.claim.TestApplication.main(TestApplication.java:29) [classes/:na]

报错信息很多,只复制最上面的报错信息

二、问题原因分析

查找了很多网上资料大不分都是说resultMap中constructor?,id*,result*,association*,collection*,discriminator这些标签书写顺序的问题,跟我遇到的实际情况不符

我的resultMap中只有id和result两个标签

我遇到问题的主要原因是在于问题原因的定位,将报错文件定位错了,所以一直没有找到问题所在

错误信息首行里面记录的报错信息很长,报错信息最前面的文件testImpl文件是自己写的,实际的报错文件DatachangeListForBiBaseDao.xml不是自己写的,忽视了,默认以为是testImpl对应的xml文件出现错了,结果查找了很多遍没有发现问题所在,而实际是因为DatachangeListForBiBaseDao.xml这个文件中的ID生成到了resultMap最下方才导致的

Error creating bean with name 'testImpl': Unsatisfied dependency expressed through field 'ciclaimplatformdwService'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'testImpl': 
Unsatisfied dependency expressed through field 'testDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'ciclaimplatformdwDao' defined in file [E:\test\target\classes\ins\claim\business\middle\dao\testDao.class]: 
Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested 
exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'sqlSessionFactory' defined in class path resource 
[org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; 
nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: '
file [E:\test\target\classes\mapper\base\middle\DatachangeListForBiBaseDao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: 
Error creating document 
instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 14; 元素类型为 "resultMap" 的内容必须匹配 "
(constructor?,id*,result*,association*,collection*,discriminator?)"。

三、解决

将DatachangeListForBiBaseDao.xml文件中resultMap中的id标签放到最上方

四、经验

报错信息及时很长,也需要认真的分析一下,不然一开始问题源头就搞错了,后面怎么查找也是白搭

 

 

上一篇:Spring XML配置文件头部字段的解析


下一篇:Spring系列之Spring常用注解总结