Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
-: Let's go ahead and take care
of our normal housekeeping work.
We'll stop all of our apps and close all of our windows.
And I'll just do a little copy-paste here
in this 04-qualifiers directory,
and I'll rename it as 05-primary.
And I'll go ahead and open this up in IntelliJ.
I'll just do a rebuild on the project.
I'll just do a quick cleanup here.
There's an old folder that we have,
our util folder.
We're not using that anymore.
I'll just delete that.
And now I'll go ahead and remove the code
for the qualifier annotation.
I'll move into this class here, demo controller.
And we had the qualifier annotation.
I'll just remove that piece of code here,
and this should fail, right,
because we have multiple implementations out here
and it's not sure which one it's gonna use.
Let's just go ahead and run it real quick just to verify.
All right, so we see the issue here.
Application failed to start, multiple implementations,
not sure which one that it should use.
We've seen all this stuff before.
Down in the action section, this is where it gave you
some hints or tips on how to resolve this issue.
All the way over to the right,
we already saw the example here of using
the qualifier annotation.
We implemented that already,
but notice here they also mentioned the primary annotation.
Hmm. Okay. So let's mark one of the beans as primary.
All right. Let's try it out.
I'll move into my TrackCoach here and expand my window,
zoom in a bit,
and I'll use the primary annotation here.
Basically what I'm saying here is since there are
multiple implementations,
then make the TrackCoach as the primary coach.
In our demo controller,
one thing to notice here,
since we're using Primary and demo controller
there's no need to use Qualifier
because we have a Primary coach.
In this example, we set it up on the TrackCoach
such to resolve any issues or questions
that Spring may have as far as which one to use.
Make use of the Primary one.
Let's go ahead and run our application,
and success. The application starts successfully.
So there's no problem,
there's no errors.
Spring knows which one of the coaches
it should use because we're making use
of the primary annotation.
Swing over into my web browser.
Go to local host 8080/daily workout,
and I should get a track workout.
Excellent.
Run a hard 5K because here we're making use
of that TrackCoach because it's primary.
Alrighty, swing back in,
and let's try and break it on purpose.
I love to do this stuff. This is always fun.
So let's go ahead and add multiple primary components
and let's see what happens.
We know that TrackCoach is already primary.
Let's go ahead and make CricketCoach primary.
All right? We're trying to add multiple primaries,
and, hey, what will Spring do?
Alrighty, so that's in place. Save that.
Your app should reload automatically,
and it's gonna reload and it's gonna fail on the reload.
So if we scroll up a bit
and take a look at the error message,
it says, "Unsatisfied dependency exception."
Okay?
In all this ugly stacked tray stuff,
they're creating bean with demo controller.
Okay?
Blah, blah, blah.
And unsatisfied dependency.
Okay?
So no qualifying bean of type coach available.
And, oh, look at this.
More than one primary bean found
among the candidates.
All right?
So Spring figured us out.
It says, "Hey, you have too many primaries out here.
You can't do that."
And so that's the main issue, that's the root cause.
Okay? And, of course, we can resolve that
by simply having a single primary component.
And so I'll just do that here by just going to CricketCoach,
removing that primary annotation, saving,
and it should reload and reload successfully.
Okay, great.
So our app is up and running and everything's up.
I can go and access that link,
and I should get the track workout on a hard 5K.
Okay, great.
All right, so this is a good example
of handling the issue of multiple implementations
by making use of the primary annotation.
And just swinging back into our demo controller here,
we see that there's no need to use Qualifier
because we actually have a primary coach,
and by swinging over to TrackCoach here,
you can see that this given TrackCoach
is marked as primary.
All right.
So good job, good job.
I'm very happy.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.