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

What if SpringBoot encounters @ Qualifier and reports an error?

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

Share

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

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!

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: 279

*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