Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory
默认类路径在spring-dao.xml
Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [spring-dao.xml]
上下文初始化期间遇到异常 - 取消刷新尝试:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory
看报错信息让我检查 com/wei/Mapper/UserMapper.xml
please check com/wei/Mapper/UserMapper.xml and file [D:\Java\Spring_Projects\Spring-10-mybatis\target\classes\com\wei\Mapper\UserMapper.xml]
总结:
得出错误出现在com/wei/Mapper/UserMapper.xml 中
检查UserMapper.xml 发现没有错误,只能去检查映射文件mybatis-config.xml 发现
UserMapper.xml中写了映射文件class加载方式
<mappers>
<mapper class="com.wei.Mapper.UserMapper"/>
</mappers>
1
2
3
而spring-dao.xml中也书写了映射文件加载方式
<property name="mapperLocations" value="classpath:com/wei/Mapper/*.xml"/>
1
总结:
两处的映射文件加载方式冲突了,所以系统报错信息才会说defined in class path resource [spring-dao.xml]