自己使用ssm框架中出现的那些问题 Failed to load ApplicationContext

ERROR [main] – Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@4da4253] to prepare test instance [com.martin.test.MybatisTest@3972a855]

java.lang.IllegalStateException: Failed to load ApplicationContext

at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)
……..

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘courseServiceImpl’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.martin.mapper.CourseMapper com.martin.service.impl.CourseServiceImpl.courseMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.martin.mapper.CourseMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userMapper’ defined in file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’: : Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘courseMapper’ defined in file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\CourseMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’: : Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘courseMapper’ defined in file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\CourseMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’: : Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userMapper’ defined in file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’: : Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSession’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\eclipse-workbace-utf8\ssm_learn2\build\classes\com\martin\mapper\Course.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 43; 必须声明元素类型 “name”。

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.martin.mapper.CourseMapper com.martin.service.impl.CourseServiceImpl.courseMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.martin.mapper.CourseMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.martin.mapper.CourseMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

就是这个错误,我查了一个上午,,,,,,,,原因是因为error太多,没找到关键的。

先说解决方法吧。

可以看到我加粗的地方,这就是根源,原因是因为我配置文件这一行的标签写错了,但是eclipse对配置文件的标签没法儿语义检查,所以一直没发现它。

感悟,认真分析报错,急着百度效率反而低。。。。。。血泪史。

    原文作者:燕大虾呀
    原文地址: https://www.jianshu.com/p/7d9126177294
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞