Python 官方文档:入门教程 => 点击学习
目录SpringBoot 无法自动装配@Autowired 报错:无法自动装配基本上是因为放到org.example下,问题解决原因无法自动装配。未找到“xxxMappe
1、项目里有类似mybatis @Mapper这种第三方映射类,需要用到springboot autoconfigration扫描解析。
2、@SpringBootApplication类,没有放到java根目录下
因为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.
真想骂他一句,约定就约定吧,能聪明点吗
Could not autowire. No beans of ‘xxxMapper’ type found.
也就是说,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文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0