@MapperScan:
1.首先了解@Mapper
    在接口上添加了@Mapper,在编译之后就会生成相应的接口实现类。
    不过需要在每个接口上面进行配置,为了简化开发,就有了 @MapperScan。

@MapperScan:

指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类。

@ComponentScan:
会自动扫描包路径下面的所有@Controller、@Service、@Repository、@Component 的类,并把符合扫描规则的类装配到spring容器中。

@MapperScan和@ComponentScan可以同时使用。

如果都是扫描的相同路径时,对于同一个接口,可能就会出现识别错误。比如

在springBoot项目的Application上面定义了

@MapperScan(basePackages = { "com" })
@SpringBootApplication
@SpringBootApplication包含了@ComponentScan。
在此项目下面有一个接口是com.xxInf,实现是com.xxImpl在实现类上面通过@Service加入spring容器中
我们在注入的时候接口时
    @Autowired
private com.xxInf xx;

可能识别的不是xxImpl,而去mybatis里面通过反射找绑定,这样就会出现BindingException错误

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

所以在设计项目结构的时候要把mapper放到一个合适的位置,通过设置MapperScan的路径basePackages 好避免这种冲突

 
												

MapperScan和ComponentScan同时使用问题的更多相关文章

  1. @MapperScan 和 @ComponentScan 区别

    1.首先@MapperScan和@ComponentScan都是扫描包 2.@ComponentScan是组件扫描注解,用来扫描@Controller  @Service  @Repository这类 ...

  2. @MapperScan和@ComponentScan的区别

    区别 今天在撸SpringBoot的时候,突然对注解产生了混淆,@MapperScan和@ComponentScan都是扫描包,二者之间有什么区别呢? 首先,@ComponentScan是组件扫描注解 ...

  3. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  4. springboot 注册dao层 service 层

    可以使用三种注解来引入DAO层的接口到spring容器中.1.@Mapper,写在每一个DAO层接口上,如下: 2.@MapperScan和@ComponentScan两者之一.前者的意义是将指定包中 ...

  5. springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

    一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx. ...

  6. 「小程序JAVA实战」springboot的后台搭建(31)

    转自:https://idig8.com/2018/08/29/xiaochengxujavashizhanspringbootdehoutaidajian31/ 根据下面的图,我们来建立下对应的sp ...

  7. spring mvc改造成spring boot

    一.新增依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  8. 聊聊、Spring ServletContainerInitializer

    我们平时用 Java 注解很多,例如 @Configuration.@Component.@Service,我们习惯于通过 XML 方式来实现 Web,而用 Java 注解方式来实现 Web 却很少. ...

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

随机推荐

  1. CentOS6.5 安装vncserver实现图形化访问

    一. 安装gnome图形化桌面 #yum groupinstall -y "X Window System" #yum groupinstall -y "Desktop& ...

  2. 关于SpringCloud配置网关转发时出现一下啊错误:“com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException”

    com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul ...

  3. Csrf_token ||| CSRF跨站请求伪造

    # 注: 部分内容参考网上,侵删   CSRF(Cross-site request forgery) 跨站请求伪造,是一种对网站的恶意利用  它会通过伪装成受信任用户的请求来利用受信任的网站来获取一 ...

  4. C#杀掉进程的方法

    C#杀掉进程的方法 private static string CmdName = "cmd"; /// <summary> /// 关闭进程 /// </sum ...

  5. 二进制32位转十进制int

    public class BinaryToDecimal { public static int BinaryToDecimal(int binaryNumber){ int decimal = 0; ...

  6. react初学之render返回加括号的问题

    刚在学习react的初始阶段,跑了一段代码 var  Mydom = React.createClass({ render:function(){ return <div> <inp ...

  7. 华莱士的 第一个python程序之(用户登录)

    Name = "shangzb"password = 43while True: _Name = input("Name:") if _Name == Name ...

  8. Adjacency matrix based Graph

    Interface AddVertex(T data) AddEdge(int from, int to) DFS BFS MST TopSort PrintGraph using System; u ...

  9. 【EMV L2】GPO响应以及AIP、AFL

    [GPO命令] 终端通过GPO(Get Processing Options)命令 通知卡片交易开始.命令数据为PDOL指定的终端数据. [GPO响应] 卡片在GPO命令的响应中返回AIP和AFL:A ...

  10. int与integer的区别

    int 是基本类型,直接存数值 integer是对象,用一个引用指向这个对象 1.Java 中的数据类型分为基本数据类型和复杂数据类型 int 是前者>>integer 是后者(也就是一个 ...