在搭建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. c# UserControl 如何在父窗口中显示Scroll

    1. UserControl 不应该是Dock = Fill, 而应该使用 Anchor 2. 父窗口(或者父控件,或者容器)的AutoScroll = True 3.UserControl 加入容器 ...

  2. IOS开发 UITabBarController

    UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程 序,ipod程序等.UITabBarContro ...

  3. iOS开发 - 多线程实现方案之NSThread篇

    NSThread API //类方法:创建一个线程 + (void)detachNewThreadWithBlock:(void (^)(void))block API_AVAILABLE(macos ...

  4. foreach循环报NPE空指针异常

    前言 最近debug时忽然发现,如果一个集合赋值为null,那么对该集合进行foreach循环(也叫增强for循环)时,会报NPE(即空指针异常NullPointerException). 代码如下: ...

  5. 两段代码实现vue路由懒加载

    const Foo = () => import('./Foo.vue') const router = new VueRouter({ routes: [ { path: '/foo', co ...

  6. 自定义的cell上面有图片时,如果产生了重用,图片可能会错乱问题

    当被重用的cell将要显示时,会调用这个方法,这个方法最大的用武之地是当你自定义的cell上面有图片时,如果产生了重用,图片可能会错乱(当图片来自异步下载时及其明显),这时我们可以重写这个方法把内容抹 ...

  7. 存储-InfluxDB

    1 TSDB influxDB是一个time series时间序列数据库. 在监控系统的开发中,大体分为采集-存储-可视化三个大类.监控指标有很显著的时间特征数据,一般采用TSDB存储. 在TSDB中 ...

  8. django项目设置

    1 项目下的文件 用于项目设定的setting.py 用于url规则匹配的urls.py 用于创建socket对象的wsgi.py 2 urls django2.0相比1.x,在url匹配语法上有很大 ...

  9. ES5数组的方法

    var ary = [1,23,4]; function isArray(o){ return Object.prototype.toString.call(o)=='[object Array]'; ...

  10. B.选点

    链接:https://ac.nowcoder.com/acm/contest/368/B 题意: 有一棵n个节点的二叉树,1为根节点,每个节点有一个值wi.现在要选出尽量多的点. 对于任意一棵子树,都 ...