整合SSM框架的项目启动Tomcat出现异常:【org.springframework.beans.factory.UnsatisfiedDependencyException】

完整异常信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeServiceImpl': Unsatisfied dependency expressed through field 'employeeMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeMapper' defined in file [D:\Java\S-S-M\target\ssm-1.0-SNAPSHOT\WEB-INF\classes\com\jia\ssm\mapper\EmployeeMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource': no matching editors or conversion strategy found

  • 由报的异常信息可以得出,无法创建自定义的employeeServiceImpl类实例,原因是通过 bean 属性 'sqlSessionFactory' 表示的未满足的依赖关系
  • 再往下看,可以看到创建类路径资源中定义了名称为“org.mybatis.spring.SqlSessionFactoryBean#0”的 Bean 时出错,因此可以判断可能是在spirng.xml配置文件中配置SqlSessionFactoryBean的时候出了问题。
  • 根据往后的内容属性“dataSource”所需的类型“javax.sql.DataSource”,说明属性为dataSource的值可能没有赋上或者出现了错误。

此时到spring.xml配置文件中去查看 

可以清楚的看到,原来是标签属性写成了 value ,由于dataSource对应的是非简单数据类型,所以应该使用 ref 属性,通过修改之后则可以正常运行


总结:

多看异常信息提示提取异常信息中简要的内容,进行一步一步分析,多结合idea开发工具的高亮提示检查正确与否,非简单数据类型的不能使用value标签属性。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值