报错信息
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘adminLoginAction’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘adminServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘adminDAOImpl’ defined in file [xxxx\software\target\software\WEB-INF\classes\cn\edu\nchu\student\dao\impl\AdminDAOImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis.cfg.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for sanxiaoNS.doCreate
解决过程(网上方法总结)
- beans 的xml里面没有配置
<context:component-scan base-package=“package-name”/> - 调用死循环
@Repository
public class ADaoImpl extends BaseDaoImpl implements ADao {
@Resource
private ADao aDao;
@Override
public int addInbox(TInbox inbox) {
....
......
aDao.delete(id);
}
@Override
public int delete(Long id) {
.....
}
}
即XyyyyDao实现里面,调用了他接口的本身方法,导致,加载ADaoImpl需要先加载完ADao,而ADao却还没有加载!
3. …
最终解决
一开始在网上搜寻各类方法,发现不存在所说的问题,因为一开始的编译是正常的,增加了一个功能模块后出现了此类问题,最后发现是Mapper.xml中的namespace没有对应:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="sanxiaoNS"> //我的是这里出现了问题,名称不匹配,修改成对应正确即可!
<resultMap id="articleResultMap" type="Article">
<id property="title" column="title"/>
<result property="time" column="time"/>
<result property="name" column="name"/>
<result property="image" column="image"/>
<result property="content" column="content"/>
<result property="file" column="file"/>
</resultMap>
<insert id="doCreate" parameterType="Article">
INSERT INTO article(title,time,name,image,content,file) VALUES (#{title},#{time},#{name},#{image},#{content}#{file})
</insert>
<select id="findAll" parameterType="java.util.List" resultMap="articleResultMap">
SELECT title,time,name,image,content,file FROM article
</select>
</mapper>