mybatis和spring整合 出现如下错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl':
Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userMapper' defined in file [D:\Program Files\java\workspaces\IdeaWorkspace\WebChat\target\WebChat\WEB-INF\classes\com\lindasoft\mapper\UserMapper.class]:
Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlSessionFactory' defined in URL [file:/D:/Program%20Files/java/workspaces/IdeaWorkspace/WebChat/target/WebChat/WEB-INF/classes/spring/applicationContext.xml]:
Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException</span>
没有其他详细的错误提示,感觉配置也没啥问题。卡住了好长时间,
网上有提示spring 和mybatis版本可能不配
于是查询一下mybatis-spring的maven库,依赖的包的版本。
http://mvnrepository.com/artifact/org.mybatis/mybatis-spring/1.3.0
于是 看到mybatis-spring版本1.3.0和 mybatis 3.4.0 以及spring 4.2.5.RELEASE版本搭配
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
最后修改为这几个版本,正常启动! done!
类似问题都可以按照这个思路来解决。
如果觉得本文对你有帮助,欢迎点赞评论,欢迎关注我,我将努力创作更多更好的文章。