springBoot项目Consider defining a bean of type 'xxx' in your configuration错误的解决

编程知识 更新时间:2023-05-02 05:34:53

我用IDEA创建一个SpringBoot项目,各种配置,mapper类和model类都检查了没有错,运行后控制台报错:

Field userMapper in com.ajax.service.J1902UserService required a bean of type ‘com.ajax.dao.J1902UserMapper’ 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 ‘com.zym_ajax.dao.J1902UserMapper’ in your configuration.

就是说我的dao类没有注入成功,我就在网上查了一下,是项目的启动类没有Mapper扫描包的注解。

类上加注解@MapperScan指明Mapper类所在包的位置供SpringBoot扫描就好啦。

@SpringBootApplication
@MapperScan("com.zym_ajax.dao")
public class ZymAjaxApplication {

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

更多推荐

springBoot项目Consider defining a bean of type 'xxx' in your configurati

本文发布于:2023-04-26 07:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/6298d0348f9567922ef24ff6714e7028.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   项目   defining   springBoot   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104691文章数
  • 26218阅读数
  • 0评论数