sqlSessionFactory无法注入,报Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
时间: 2023-10-13 19:04:19 浏览: 113
针对没有sessionFactory问题的情况之一
5星 · 资源好评率100%
当报错提示"Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"时,这意味着在配置中遗漏了注入sqlSessionFactory或sqlSessionTemplate的必要属性。解决这个问题的方法是在dao的基类中使用注解方式给SqlSessionDaoSupport注入SqlSessionFactory或SqlSessionTemplate。可以参考以下解决办法:在dao的基类中使用注解@Repository("daoSuper")和@Scope("singleton")声明该类为dao的基类,并使用@Resource注解给SqlSessionDaoSupport注入SqlSessionFactory,代码示例如下:
```java
@Repository("daoSuper")
@Scope("singleton")
public class DaoSuperImpl extends SqlSessionDaoSupport {
@Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
super.setSqlSessionFactory(sqlSessionFactory);
}
// ...
}
```
这样就能解决sqlSessionFactory无法注入的问题了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required](https://blog.csdn.net/weixin_33743703/article/details/93460008)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [sqlSessionFactory无法注入,报Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required](https://blog.csdn.net/qq_37502106/article/details/80484939)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文