Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that SpringBoot automatic assembly bean can not find the type

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to solve the problem that SpringBoot automatic assembly bean can not find the type", the editor shows you the operation process through the actual case, the operation method is simple and fast, and practical. I hope that this article "how to solve the problem of SpringBoot automatic assembly bean can not find the type" article can help you solve the problem.

SpringBoot Auto Assembly bean cannot find the type

@ Autowired based on Spring annotations is a common automatic assembly annotation, but due to personal negligence, SSM does not scan the corresponding bean package when it is configured, or when using Boot, it does not put it under the package and its subpackages of the startup class, resulting in an error.

Today, I made a problem because boot couldn't scan the bag.

Description:

Field empApi in feign_consumer.demo.controller.testController required a bean of type 'api.eApi' 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 'api.eApi' in your configuration.

Process finished with exit code 1

Read the wrong report, it is obvious that the Bean; can not be found, in other words, the bean object is not assembled into the Spring container, resulting in assembly missing at startup.

Look at the project structure

It's obvious.

When boot starts, the feign_consumer.demo package and its subpackages are scanned, and the bean that needs to be assembled is only under the api package. Spring will not scan the api package at startup (unless @ ComponentScan is used to change the convention). So it will cause the project to start with an error.

This also reminds us that using modular development should pay attention to the integrity of the project and its engineering structure; in addition, the code specification is also important.

Unable to assemble automatically. Bean of type "xxxMapper" not found

Could not autowire. No beans of 'xxxMapper' type found.

It shows that the Spring framework does not recognize the classes in your xxxMapper, that is to say, the classes of xxxMapper are not managed by the Spring framework, if you need the classes to be managed by Spring, then you have to add @ Repository annotations to him, so that he will not report errors when you automatically inject them into the service layer.

If your class does not need to manage or inherit or implement some rules, and the program does not generate 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.

This is the end of the content about "how to solve the problem that SpringBoot automatic assembly bean can not find the type". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report