mybatis expected at least 1 bean which qualifies as autowire candidate for this dependency
错误原因:没有引入相应mapper接口,导致spring没有找到依赖
解决方法一:使用注解的方法:
首先在spring配置文件中添加
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.forum" />
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
然后在mapper接口中添加注解
@Transactional
@Repository
public interface RoleMapper
解决方法二:使用xml配置定义mapper的bean
<!— mapper bean -->
<bean id="roleMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="mapperInterface" value="com.forum.dao.RoleMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
不过第二种方法有点繁琐,假如有多个mapper接口的时候,可能要配置多个bean,那就太多了,能把文件撑爆。
mybatis expected at least 1 bean which qualifies as autowire candidate for this dependency的更多相关文章
- NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
报错如下: NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at l ...
- No matching bean of type [xx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
这个看起来很弱爆的问题其实是因为其他的配置文件中已经出现了为xx定义好的注入.如果用@Autowired就会得到上面的错误 , 但是用@Resource的时候就会看到类似下面的错误 Bean name ...
- Caused by:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type "" available: expected at least 1 bean which qualifies as autowire candidate
项目使用spring, mybatis.因为分了多个模块,所以会这个模块引用了其它模块的现在,结果使用Junit测试的时候发现有两个模块不能自动注入dao和service问题.解决后在此记录一下. 解 ...
- spring加载bean报错:expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
看具体报错日志: 警告: Unable to proxy interface-implementing method [public final void cn.wlf.selection.proto ...
- springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题
Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...
- NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate
在搭建SSM spring springmvc mybatis整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
- 【java异常】expected at least 1 bean which qualifies as autowire candidate for this depende
1.查看接口实现类是否加入注解,如service.repository等 2.查看spring配置文件是否自动扫描包 <context:component-scan base-packag ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注 ...
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.thinkplatform.dao.UserLogDao' available: expected at least 1 bean which qualifies as autowi
我出错的问题是: 检查:
随机推荐
- window环境下备份与恢复(实际操作)
C:\Documents and Settings\xuzhengzhu>sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on ...
- LINUX提权后获取敏感信息之方法
文中的每行为一条命令,文中有的命令可能在你的主机上敲不出来,因为它可能是在其他版本的linux中所使用的命令. 列举关键点 (Linux)的提权是怎么一回事: 收集 – 枚举,枚举和一些更多的枚举. ...
- SQL 之 Group By
SQL 之 Group By Group By从字面意义上理解就是根据By指定的规则对数据进行分组,所谓的分组就是将一个数据表划分成若干个小区域. 例如:有这么一张表
- 开源 SHOPNC B2B2C结算营运版 wap IM客服 API 手机app 短信通知
源码我们这里简单的测试了下,具体的请自行下载测试.这套源码官方售价很高,在这里完全免费分享,无任何限制,安装也简单. 源码下载后请自行检测安全,在使用过程中发生的任何问题请自行处理,本站不承担任何责任 ...
- Node.js monly图片批量下载爬虫1.00
此爬虫又用到了iconv转码,代码如下: //====================================================== // mmonly图片批量下载爬虫1.00 ...
- 利用Referer请求头阻止"盗链"
转自:http://wisdomsong2007.blog.163.com/blog/static/47783725200882523820664/ 前言 有一些站点自己没有提供下载空间,但是为了吸引 ...
- java中的Annotation
java中包含5个基本的Annotation: @Override @Deprecated @SuppressWarnings @SafeVarargs @FunctionalInterface …… ...
- leetcode第一刷_Combination Sum Combination Sum II
啊啊啊啊.好怀念这样的用递归保存路径然后打印出来的题目啊.好久没遇到了. 分了两种,一种是能够反复使用数组中数字的,一种是每一个数字仅仅能用一次的.事实上没有多大差别,第一种每次进入递归的时候都要从头 ...
- Unity3D系列教程--使用免费工具在Unity3D中开发2D游戏 第一节
声明: 本博客文章翻译类别的均为个人翻译,版权全部.出处: http://blog.csdn.net/ml3947,个人博客:http://www.wjfxgame.com. 译者说明:这是一个系 ...
- ubuntu14.04无法连接有线连接问题
在windows系统下关闭有线网卡的关机,自动唤醒功能即可