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