Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,230 --> 00:00:02,790
Instructor: Let's take care of our normal Housekeeping,
2
00:00:02,790 --> 00:00:05,163
stopping all apps and closing all windows.
3
00:00:18,720 --> 00:00:19,770
And in my file system here,
4
00:00:19,770 --> 00:00:21,810
I'll just do a copy paste on this project.
5
00:00:21,810 --> 00:00:23,830
O six lazy initialization
6
00:00:25,020 --> 00:00:28,503
and I'll rename it as O seven bean scopes.
7
00:00:32,580 --> 00:00:35,883
And then I'll go ahead and open this up in IntelliJ.
8
00:00:42,063 --> 00:00:45,146
I'll do a rebuild on the project here
9
00:00:47,130 --> 00:00:49,380
and I'll remove the lazy initialization
10
00:00:49,380 --> 00:00:53,133
and I'll also remove the global configuration for lazy-init.
11
00:01:02,130 --> 00:01:03,900
I'll open up the application properties here
12
00:01:03,900 --> 00:01:05,853
and just remove that configuration.
13
00:01:17,880 --> 00:01:20,220
And then I'll do a similar thing here on the track coach,
14
00:01:20,220 --> 00:01:21,810
remove that lazy annotation.
15
00:01:21,810 --> 00:01:23,370
And again, just cleaning up,
16
00:01:23,370 --> 00:01:25,620
just so I have some basic code to start with.
17
00:01:32,820 --> 00:01:33,720
All right, so let's go ahead
18
00:01:33,720 --> 00:01:35,670
and move into our demo controller here
19
00:01:35,670 --> 00:01:38,073
and let's add a new field.
20
00:01:41,940 --> 00:01:44,890
I'll create this coach, another coach
21
00:01:52,955 --> 00:01:57,955
and then I'll update my constructor to inject another coach.
22
00:02:14,761 --> 00:02:17,483
Here I have qualifier and I have cricket coach
23
00:02:25,560 --> 00:02:28,323
and then I have coach the another coach.
24
00:02:31,740 --> 00:02:33,240
And then inside of this constructor here,
25
00:02:33,240 --> 00:02:35,670
I make the appropriate assignments.
26
00:02:35,670 --> 00:02:39,303
So I'll have another coach equals the another coach.
27
00:02:47,100 --> 00:02:48,690
All right so that's our new constructor,
28
00:02:48,690 --> 00:02:50,280
that has been updated here.
29
00:02:50,280 --> 00:02:51,990
And again, a couple things to point out here.
30
00:02:51,990 --> 00:02:53,910
The default scope is singleton,
31
00:02:53,910 --> 00:02:55,740
so all dependency injections for the bean,
32
00:02:55,740 --> 00:02:57,813
will reference the same bean.
33
00:03:03,660 --> 00:03:05,250
Let's also add some code here at the bottom,
34
00:03:05,250 --> 00:03:07,233
to check the bean scopes.
35
00:03:12,750 --> 00:03:14,490
So I'll just stretch out here at the bottom,
36
00:03:14,490 --> 00:03:16,240
give myself some room to work with.
37
00:03:22,203 --> 00:03:25,730
I'll add this new get mapping slash check
38
00:03:39,420 --> 00:03:42,393
and I'll return comparing beans.
39
00:03:57,660 --> 00:03:59,610
And in parens, I'll give my coach,
40
00:03:59,610 --> 00:04:01,620
equals equals another coach,
41
00:04:01,620 --> 00:04:04,323
just to see if they point to the same thing.
42
00:04:11,520 --> 00:04:12,900
Okay, so again, we're checking to see,
43
00:04:12,900 --> 00:04:14,040
if this is the same beans.
44
00:04:14,040 --> 00:04:16,019
So true or false, depending on the bean scope.
45
00:04:16,019 --> 00:04:18,120
If it's singleton, it should return true,
46
00:04:18,120 --> 00:04:19,743
prototype return false.
47
00:04:25,890 --> 00:04:27,330
All righty, so we'll swing out here
48
00:04:27,330 --> 00:04:29,530
and we'll go ahead and run this application.
49
00:04:32,980 --> 00:04:35,313
Okay, so our application is up and running.
50
00:04:44,614 --> 00:04:45,990
Open up our browser.
51
00:04:45,990 --> 00:04:49,923
Just go to this local host 8080 slash check.
52
00:04:52,530 --> 00:04:53,363
All righty, great.
53
00:04:53,363 --> 00:04:55,380
So we're checking to see if this is the same bean.
54
00:04:55,380 --> 00:04:57,390
By default we have singleton scope,
55
00:04:57,390 --> 00:05:00,003
hence true, this kind of works out as desired.
56
00:05:05,040 --> 00:05:08,103
Now let's swing back into our application code here.
57
00:05:10,830 --> 00:05:13,140
And now what I wanna do is move over to the cricket coach
58
00:05:13,140 --> 00:05:15,363
and change the bean scope to prototype.
59
00:05:39,390 --> 00:05:41,410
I make use of the scope annotation
60
00:05:56,250 --> 00:05:58,893
and then I choose scope of prototype.
61
00:06:01,800 --> 00:06:03,720
Now remember with this prototype scope,
62
00:06:03,720 --> 00:06:06,633
a new object instance is created for each injection.
63
00:06:16,680 --> 00:06:18,450
And now swinging back over to the controller,
64
00:06:18,450 --> 00:06:20,430
just as a refresh here with prototype scope,
65
00:06:20,430 --> 00:06:22,380
new object instance for each injection.
66
00:06:23,280 --> 00:06:25,680
And so out there we'll have two different objects,
67
00:06:25,680 --> 00:06:28,290
that are injected and so they won't point to the same.
68
00:06:28,290 --> 00:06:31,293
So this should return false for us.
69
00:06:39,120 --> 00:06:41,520
So now browser, move over here and do a reload
70
00:06:41,520 --> 00:06:43,410
and excellent false.
71
00:06:43,410 --> 00:06:45,600
So again, we're checking to see if it's the same bean,
72
00:06:45,600 --> 00:06:48,360
since we have prototype scope, hence false,
73
00:06:48,360 --> 00:06:51,360
because we have two separate objects that were created
74
00:06:51,360 --> 00:06:53,883
and it's not pointing to the exact same object.
75
00:06:55,200 --> 00:06:56,970
All right, so this kind of works out as desired.
76
00:06:56,970 --> 00:06:59,490
A good example here of using scopes,
77
00:06:59,490 --> 00:07:03,000
the default singleton scope, and also the prototype scope.
78
00:07:03,000 --> 00:07:06,213
So I'd like to say good job my friend.
6165
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.