在搭建SSM spring springmvc  mybatis整合的时候, 遇到了这个问题

说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息。一看加载的是spring.xml文件,就去这个文件中查找了。

这个错误是因为自动扫描包配置出错。无法自动注入类到容器中

       <!--配置自动扫描的包,用于注解的扫描@Service @Controller-->
<context:component-scan base-package="com.bj186.crm"></context:component-scan> <!--通过bean配置自动扫描并加载mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bj186.crm.mapper"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

正确设置好这段代码之后, 问题解决!

@Service("UserService")
public class UserServiceImpl implements UserService { @Resource
private EmployeeMapper employeeMapper; public Employee selectEmployeeById(Integer eid) {
return employeeMapper.selectByPrimaryKey(eid);
}
}

参考资料: https://blog.csdn.net/Q_Sea__/article/details/79832569

https://blog.csdn.net/qq_38003454/article/details/80015389

NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate的更多相关文章

  1. springboot启动报错:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.zxkj.lockserver.dao.CompanyDao' available: expected at least 1 bean which qua

    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of ty ...

  2. MyBatis Plus:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4

    场景: 应用MyBatis Plus 和通用Mapper 继承自ServiceImpl实现对Service里的方法进行包装再处理. public interface IServiceBase2< ...

  3. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qingmu.mybaitsplus.mapper.UserMapper' available:

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...

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

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

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

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

  7. springboot 启动报错Consider defining a bean of type 'com.example.springbootdruid.mapper.UserMapper' in your configurati

    一.问题 springboot项目启动时报错: Field userMapper in com.example.springbootdruid.service.impl.UserServiceImpl ...

  8. Java报错: A component required a bean of type 'com.sirifeng.testmybatis.mapper.BookMapper' that could not be found.

    在学习Spring-boot-mybatis时,报错A component required a bean of type 'com.sirifeng.testmybatis.mapper.BookM ...

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

随机推荐

  1. 查看python 3中的内置函数列表,以及函数功能描述

    >>> dir(__builtins__)//查看内置函数(BIF)列表 ['ArithmeticError', 'AssertionError', 'AttributeError' ...

  2. Fitnesse的一个简单实例

    Fixture 代码 package eg; import org.joda.time.DateTime; public class JodaTime { int year; public Strin ...

  3. Node.js学习(第四章:初见express)

    Express框架是一款简洁而灵活的node.js web应用框架.前面我们自己手动创建服务器在Express中就是一个API的事情,这就使得我们更加注重业务的功能和开发效率上,不必纠结过多底层的事情 ...

  4. PhpStorm之操作数据库

    对数据库进行基本的操作 还不清楚如何使用PhpStorm连接本地数据库的朋友看一下我的上一篇博客配置数据库连接 点击已经连接好的数据库,找到下图中的 Consoles,然后点击 console(def ...

  5. C++里的强制类型转换符reinterpret_cast、static_cast 、dynamic_cast、const_cast 区别

    C 风格(C-style)强制转型如下: (T) exdivssion // cast exdivssion to be of type T 函数风格(Function-style)强制转型使用这样的 ...

  6. perl C/C++ 扩展(一)

    通过h2xs 中间件,我们可以快速的使用c或则C++ 库来实现perl 扩展功能 第一讲:跑通hello world 程序******************************我们使用命令:h2 ...

  7. 3.Python自我修炼(升仙中....整数,布尔值,字符串,for循环)

    python学习(整数,布尔值,字符串,for循环) 1.整数 ​ 在python3中所有的整数都是int类型. 但在python2中如果数据量比较大. 会使用long类型.但是在python3中不存 ...

  8. 第三篇 Nosql讲解之windows下Memcached和Memcache的区别安装(二)

    一.Memcached和Memcache的区别: 网上关于Memcached和Memcache的区别的理解众说纷纭,我个人的理解是: Memcached是一个内存缓存系统,而Memcache是php的 ...

  9. 三维BFS Poj 2251

    #include <iostream> #include <cstdio> #include <string> #include <cstring> # ...

  10. GYM 101889I(mst+lca)

    最小生成树上倍增询问裸的. const int maxn = 2e5 + 5; int n, m, q; //图 struct Edge { int u, v; ll cost; bool opera ...