关于@ComonentScan和@MapperScan注释的冲突问题

SpringBoot项目web模块的启动类本来是这样写的:

@ComponentScan("cn.onesdream")
@MapperScan("cn.onesdream")
@SpringBootApplication
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

}
之前一直以为,包扫描的范围写的大一点其实也没有什么,至多就是影响一点扫描的速度。
但是,在今天出现了一个问题,当调用一个接口的时候,报500的错误,查看控制台发现提示有一个类方法不能找到,错误如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.onesdream.service.ArticleSerive.list
......

执行maven中的install命令,报错如下:

Description:

Field articleMapper in cn.onesdream.service.impl.ArticleServiceImpl required a bean of type 'cn.onesdream.dao.mapper.ArticleMapper' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'cn.onesdream.dao.mapper.ArticleMapper' in your configuration.
......

一直折腾了很久,还是没有解决,这个问题实在怪异,明明是有的类啊。
然后无意中发现启动时的控制台有两条警告信息:

2020-05-23 17:49:25.515  WARN 16900 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'articleMapper' and 'cn.onesdream.dao.mapper.ArticleMapper' mapperInterface. Bean already defined with the same name!
2020-05-23 17:49:25.516  WARN 16900 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'regdataMapper' and 'cn.onesdream.dao.mapper.RegdataMapper' mapperInterface. Bean already defined with the same name!

看到这两个警告才开始意识到这两个包扫描之间有了冲突。
于是修改启动类:

@ComponentScan("cn.onesdream")
@MapperScan("cn.onesdream.dao.mapper")
@SpringBootApplication
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

}

启动,一切正常。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值