Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,200 --> 00:00:02,940
Instructor: In this video will cover Annotation
2
00:00:02,940 --> 00:00:05,283
Autowiring and Qualifiers.
3
00:00:09,360 --> 00:00:10,230
For auto wiring,
4
00:00:10,230 --> 00:00:12,360
we're injecting a coach implementation.
5
00:00:12,360 --> 00:00:14,520
So, Spring will scan for components,
6
00:00:14,520 --> 00:00:17,700
check to see if anyone implements a given coach interface.
7
00:00:17,700 --> 00:00:19,500
If so, let's inject them.
8
00:00:19,500 --> 00:00:23,051
But if we have multiple implementations, which one,
9
00:00:23,051 --> 00:00:26,460
like what algorithm will Spring use to determine
10
00:00:26,460 --> 00:00:28,743
which coach that it should implement? Hmm.
11
00:00:31,770 --> 00:00:32,790
So, here's a diagram here
12
00:00:32,790 --> 00:00:34,740
of our multiple coach implementations.
13
00:00:34,740 --> 00:00:36,990
So, we have coach, cricket coach,
14
00:00:36,990 --> 00:00:40,143
baseball coach, track coach, tennis coach, et cetera.
15
00:00:43,650 --> 00:00:45,630
And then, we have the actual source code
16
00:00:45,630 --> 00:00:47,370
for these implementations.
17
00:00:47,370 --> 00:00:51,330
So, we have our cricket coach, baseball, track and tennis.
18
00:00:51,330 --> 00:00:52,926
All implement the coach interface.
19
00:00:52,926 --> 00:00:55,140
So, when we ask for a coach implementation,
20
00:00:55,140 --> 00:00:56,673
which one will Spring pick?
21
00:00:59,190 --> 00:01:01,503
Well, we have a little problem.
22
00:01:02,460 --> 00:01:04,170
So, this is the error message that you'll actually
23
00:01:04,170 --> 00:01:06,930
encounter when you run your application.
24
00:01:06,930 --> 00:01:10,200
Spring will say there's a parameter zero of the constructor
25
00:01:10,200 --> 00:01:13,260
and the controller required a single bean,
26
00:01:13,260 --> 00:01:15,060
but four were found.
27
00:01:15,060 --> 00:01:17,250
Okay so, I need a coach,
28
00:01:17,250 --> 00:01:18,990
but there's too many of them out here.
29
00:01:18,990 --> 00:01:20,910
And at this point, Spring will not start up.
30
00:01:20,910 --> 00:01:22,290
The application will not start
31
00:01:22,290 --> 00:01:24,240
because there's too much ambiguity.
32
00:01:24,240 --> 00:01:26,823
Spring can't figure out which one you want.
33
00:01:30,600 --> 00:01:32,850
So, one solution here is to be specific
34
00:01:32,850 --> 00:01:35,500
and that's by making use of the qualifier annotation.
35
00:01:37,110 --> 00:01:40,500
And so, here's our coding here for our demo controller.
36
00:01:40,500 --> 00:01:41,700
And everything looks the same except
37
00:01:41,700 --> 00:01:44,550
for this one new entry here for qualifier.
38
00:01:44,550 --> 00:01:46,380
So, here we give qualifier
39
00:01:46,380 --> 00:01:49,680
and then we specify the bean ID of cricket coach.
40
00:01:49,680 --> 00:01:52,140
Now the bean ID has the same name
41
00:01:52,140 --> 00:01:56,040
as the class except for the first character as lowercase.
42
00:01:56,040 --> 00:01:57,000
All right. So, that's how we come
43
00:01:57,000 --> 00:01:59,370
up with cricket coach here, starting with lower case.
44
00:01:59,370 --> 00:02:00,660
And this will actually resolve the issue
45
00:02:00,660 --> 00:02:02,190
because now we're being very specific.
46
00:02:02,190 --> 00:02:04,320
We're saying, hey, use cricket coach
47
00:02:04,320 --> 00:02:06,543
as the injection for this given item.
48
00:02:07,900 --> 00:02:10,020
And there's other bean IDs out there that we could use
49
00:02:10,020 --> 00:02:12,660
such as baseball coach, track coach, or tennis coach.
50
00:02:12,660 --> 00:02:13,920
But in this scenario here,
51
00:02:13,920 --> 00:02:15,820
we're making use of the cricket coach.
52
00:02:19,530 --> 00:02:22,080
Now that's for constructor injection.
53
00:02:22,080 --> 00:02:24,360
For setter injection, you can do a similar thing.
54
00:02:24,360 --> 00:02:26,673
You can also use the qualifier annotation.
55
00:02:29,670 --> 00:02:31,050
And then, here's our code examples,
56
00:02:31,050 --> 00:02:33,450
our normal setter method set coach
57
00:02:33,450 --> 00:02:36,240
and then we specify qualifier annotation
58
00:02:36,240 --> 00:02:37,530
and then give cricket coach.
59
00:02:37,530 --> 00:02:40,290
Again, the bean ID is the same name as the class
60
00:02:40,290 --> 00:02:42,993
except for the first character is lowercase.
61
00:02:44,280 --> 00:02:45,330
All righty, this looks pretty good.
62
00:02:45,330 --> 00:02:46,740
Let's go ahead and move into our (indistinct)
63
00:02:46,740 --> 00:02:48,243
and let's write the code.
4929
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.