Spring Error : No unique bean of type [org.apache.ibatis.session.SqlSessionFactory] is defined


报错信息:

Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.apache.ibatis.session.SqlSessionFactory] is defined: expected single matching bean but found 2...
 

原因:

beans.xml 中定义了两个 SqlSessionFactory bean,而在 SqlSessionDaoSupport 中调用了下面 setSqlSessionFactory(),造成了不唯一。
 
1 @Autowired(required = false)
2   public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
3     if (! this.externalSqlSession ) {
4       this. sqlSession = new SqlSessionTemplate(sqlSessionFactory);
5     }
6   }
 

解决方案:

修改 beans.xml 中与 SqlSessionFactory bean 相关的配置。

 
 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM