广告
返回顶部
首页 > 资讯 > 后端开发 > Python >springboot 无法自动装配的问题
  • 718
分享到

springboot 无法自动装配的问题

2024-04-02 19:04:59 718人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录SpringBoot 无法自动装配@Autowired 报错:无法自动装配基本上是因为放到org.example下,问题解决原因无法自动装配。未找到“xxxMappe

springboot 无法自动装配

@Autowired 报错:无法自动装配

基本上是因为

1、项目里有类似mybatis @Mapper这种第三方映射类,需要用到springboot autoconfigration扫描解析。

2、@SpringBootApplication类,没有放到java根目录下

放到org.example下,问题解决

原因

因为springboot只扫描@SpringBootApplication类目录及子目录下的自动配置:

For example, it will be used when scanning for @Entity classes. It is generally recommended that you place @EnableAutoConfiguration (if you're not using @SpringBootApplication) in a root package so that all sub-packages and classes can be searched.

真想骂他一句,约定就约定吧,能聪明点吗

无法自动装配。未找到“xxxMapper”类型的bean

Could not autowire. No beans of ‘xxxMapper’ type found.

说明Spring框架没有识别到你的xxxMapper中的类

也就是说,xxxMapper的类没有被Spring框架给管理,如果你所需要的类需要给Spring给管理,那么你得在他上面加上@Repository注解,这样你在service层自动注入时他才不会报错。

如果你得类不需要管理或者继承或实现一些规则

并且程序没有产生一些错误,那么这些都是可以被允许的。

@Repository
public interface AdminMapper  {
    public void xxx(){}
}
public class AdminServiceImpl  {
    @Autowired
    private AdminMapper adminMapper;
    }

这样他就不会报错了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: springboot 无法自动装配的问题

本文链接: https://www.lsjlt.com/news/162971.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作