In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to solve the problem that springboot can not automatically assemble. The content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Springboot cannot auto-assemble @ Autowired error: cannot auto-assemble
Basically because
1. There is a third-party mapping class such as mybatis @ Mapper in the project, which requires springboot autoconfigration scanning and parsing.
2. @ SpringBootApplication class, which is not placed in the java root directory
Put it under org.example and solve the problem.
Reason
Because springboot only scans the @ SpringBootApplication class directory and subdirectories for automatic configuration:
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.
I really want to scold him. Let's make a deal. Can you be smart?
Unable to assemble automatically. Bean of type "xxxMapper" not found
Could not autowire. No beans of 'xxxMapper' type found.
Indicates that the Spring framework does not recognize the classes in your xxxMapper
In other words, the class of xxxMapper is not managed by the Spring framework, so if the class you need needs to be managed by Spring, you have to annotate it with @ Repository, so that he won't report an error when you inject it automatically in the service layer.
If your class does not need to manage or inherit or implement some rules
And the program does not produce any errors, then these can be allowed.
@ Repositorypublic interface AdminMapper {public void xxx () {}} public class AdminServiceImpl {@ Autowired private AdminMapper adminMapper;}
So he won't make a mistake.
What is springboot? springboot is a new programming specification, which is designed to simplify the initial construction and development process of new Spring applications. SpringBoot is also a framework that serves the framework, and the scope of services is to simplify configuration files.
The above content is how to solve the problem that springboot can not automatically assemble. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.