org.springframework.beans.factory.BeanCreationException:sqlSessionFactory创建失败

配置文件出现问题,报错的原因在于创建sqlsessionfactroy失败(这个坑确实比较隐晦)

Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [ssm/mybatis/mapper*.xml]: ServletContext resource [/ssm/mybatis/] cannot be resolved to URL because it does not exist

 

看详细的设置之后,不论是eclipse还是idea开发,关键是配置sqlSessionFactory个路径是用“.”还是用“/”表示,还有是ref还是value等。网上的教程有的时间比较老,所以多尝试几次

我用的是eclipse开发,是在applicationContext.xml文件中,创建SqlSessionFactory出现了问题,报错的主要是在处理sql文件映射时

这里处理问题的关键是,在路径下加了类路径classpath,在该目录下去寻找mapper的映射文件,就解决该问题了

<property name="mapperLocations" value="classpath:ssm/mybatis/mapper/*.xml"/>   

另外:还有一个经常出错的原因是多级目录建立的原因 :例如(之前看个博客上有人回复)

<mappers> <mapper resource="com.abc.mybatis.dao/EmployeesMapper.xml"/> com.abc.mybatis.dao/EmployeesMapper.xml <!--<mapper resource="EmployeesMapper.xml"/>--> </mappers> 建立的多级目录有问题,仔细看看是com.abc.mybatis.dao还是com/abc/mybatis/dao

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值