V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cway
V2EX  ›  Java

mybatis plus 报错求助 百度没百到求助

  •  
  •   cway · 2019-07-03 09:59:45 +08:00 · 5563 次点击
    这是一个创建于 1730 天前的主题,其中的信息可能已经有所发展或是发生改变。

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forecastServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.baomidou.mybatisplus.mapper.BaseMapper com.baomidou.mybatisplus.service.impl.ServiceImpl.baseMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.baomidou.mybatisplus.mapper.BaseMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 实在不知道哪里错了,求助大家帮搜搜

    11 条回复    2019-07-19 09:57:18 +08:00
    dovme
        1
    dovme  
       2019-07-03 10:20:00 +08:00
    forecastServiceImpl 加 @Service 注解了吗?
    fooving
        2
    fooving  
       2019-07-03 10:44:51 +08:00
    baseMapper 是接口吧?
    是不是在 forecastServiceImpl 有
    @autowire
    baseMapper

    ?接口是不能 autowire 的
    tudouxiong
        3
    tudouxiong  
       2019-07-03 11:14:19 +08:00 via Android   ❤️ 1
    上 stackoverflow 求助 ✘
    上 V2EX 求助 ✔
    wc951
        4
    wc951  
       2019-07-03 14:32:05 +08:00 via Android
    这和 mybatis 有什么关系,这不就是 spring 注入失败了吗
    cway
        5
    cway  
    OP
       2019-07-03 17:18:58 +08:00
    @dovme 都加了,Mapper 中也加了 @Mapper 注解

    @fooving baseMapper 是 mybatis plus 自己的代码吧

    @wc951 就是不知道哪里出错了呀

    发现个奇怪的问题,我用 SpringBoot 用之前代码没问题,,但是我换成普通 lib 中放 jar 形式的项目就不行,同样的代码。
    jinue9900
        6
    jinue9900  
       2019-07-03 18:52:23 +08:00
    @cway 你不是一个 maven 工程么,要么可能有 starter 要么就是配置没配好
    cluulzz
        7
    cluulzz  
       2019-07-03 23:31:54 +08:00
    MotherShip
        8
    MotherShip  
       2019-07-04 10:46:27 +08:00
    这是 Mybatis Plus 把
    你说 SBoot 可以 SSM 不行,估计是少了什么 starter 中的配置,没配包扫描之类的。。
    cway
        9
    cway  
    OP
       2019-07-05 08:40:42 +08:00
    @jinue9900 明显不是,是导 jar 包的 ssm 工程,虽然落后了点但是只能这样
    @MotherShip 所以不知道什么问题呀
    hafuhafu
        10
    hafuhafu  
       2019-07-09 08:22:22 +08:00
    入口类上加注解 @MapperScan(mapper 包名)
    大概
    jaylee4869
        11
    jaylee4869  
       2019-07-19 09:57:18 +08:00
    BaseMapper 打上 @Repository 或者 @Mapper 看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   940 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:31 · PVG 05:31 · LAX 14:31 · JFK 17:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.