Get the App
SLTechnology News&Howtos  ›  Development  › 

What if SpringBoot encounters @ Qualifier and reports an error?

Shulou Source: shulou.com Published: 2022-06-01 08:30:36 10月02日 Update

This article mainly shows you "SpringBoot encounter @ Qualifier error report how to do", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "SpringBoot encounter @ Qualifier error report how to do" this article.

The pit @ Qualifier encountered by SpringBoot reported red.

@ Qualifier always reports red when writing a project. Only after searching for a long time did you know that when idea generated the project, putting the main configured classes in a package caused the default package structure scan to change and the components you defined could not be scanned. For more information, you can take a look at the SpirngBoot default package structure rules.

Solution method

The main configuration class must be placed on the parent package that is the package you are scanning

Usage of SpringBoot annotations @ Qualifier

I need to inject service into Controller, so my server has two implementation classes. How can I tell the difference between the two impl?

There is a slight difference in the way it is implemented depending on the annotations of the injected resources.

The upper bedding map below

Please ignore my red line.

# # when using @ Autowired injection in Controller

Qualifier means qualified, and this flag indicates which implementation class we need. Add the @ Qualifier annotation, and note that the parameter name of @ Qualifier is one of the names of the @ Service annotation we defined earlier.

# # when using @ Resource injection

It's easier to use @ resource injection. Val with "name" is one of the names of @ Service annotations.

The above is all the contents of the article "what to do if SpringBoot encounters @ Qualifier error report". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Comments what to do content name article two time structure project learning help configuration different upper berth parameters qualified that is meaning way method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker macOS Apple Shulou Information