错误原因:没有引入相应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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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问题.解决后在此记录一下. 解 ...

  4. 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 ...

  5. springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题

    Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...

  6. 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整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...

  7. 【java异常】expected at least 1 bean which qualifies as autowire candidate for this depende

    1.查看接口实现类是否加入注解,如service.repository等 2.查看spring配置文件是否自动扫描包    <context:component-scan base-packag ...

  8. 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扫描注 ...

  9. 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

    我出错的问题是: 检查:

随机推荐

  1. ylbtech-LanguageSamples-Indexers(索引器)

    ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Indexers(索引器) 1.A,示例(Sample) 返回顶部 “索引器”示例 本示 ...

  2. 自制DEV皮肤

    1.打开DEV自带的皮肤制作工具 2.创建一个新的皮肤工程[File][New] 3.改变指定控件的颜色,比如背景色 4.改变控件边框的颜色.粗细

  3. 配置Eclipse自动编译NDK/JNI

    Eclipse关联ndk-build(自建Builder方法)  1. Project->Properties->Builders->New,新建一个Builder 2. 参数配置 ...

  4. 如何使用 awk 输出文本中的字段和列

    首先我们要知道,awk 能够自动将输入的行,分隔为若干字段.每一个字段就是一组字符,它们和其他的字段由一个内部字段分隔符分隔开来. 如果你熟悉 Unix/Linux 或者懂得 bash shell 编 ...

  5. How to make an executable jar file?

    https://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file 文件的路径如下: package com. ...

  6. [Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers

    Redux provides a convenient helper for combining many reducers called combineReducer, but it focuses ...

  7. meta文件是什么东西

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...

  8. Win7无法安装Flash Player怎么办

    在IE的工具选项中把安全选项中的ActiveX控件一系列都改为启用即可.

  9. windows print 自定义字体颜色【python】

    windows print 自定义字体颜色 import ctypes STD_INPUT_HANDLE = -10 STD_OUTPUT_HANDLE= -11 STD_ERROR_HANDLE = ...

  10. Odoo8.0安装wkhtmltopdf报表运行环境

    #下载   #注意根据操作系统选择相应版本   (旧地址)wget http://sourceforge.net/projects/wkhtmltopdf/files/0.12.1/wkhtmltox ...