Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,410 --> 00:00:02,460
Instructor: Now we can go ahead
2
00:00:02,460 --> 00:00:05,313
and start our application and test it out.
3
00:00:08,070 --> 00:00:09,510
And when we look at the logs here
4
00:00:09,510 --> 00:00:11,250
we can see that we have all
5
00:00:11,250 --> 00:00:13,710
of these constructor print line statements here
6
00:00:13,710 --> 00:00:16,110
for baseball coach, cricket coach, and so on.
7
00:00:16,110 --> 00:00:18,510
So notice here all the beans are created
8
00:00:18,510 --> 00:00:20,133
at application startup.
9
00:00:21,930 --> 00:00:24,963
Now let's go ahead and mark the track coach as lazy.
10
00:00:30,720 --> 00:00:33,400
I'll open up my track coach implementation here
11
00:00:34,530 --> 00:00:38,493
and I'll simply annotate it with the lazy annotation.
12
00:00:45,900 --> 00:00:49,830
Alrighty and so now when we run our application again
13
00:00:49,830 --> 00:00:52,080
we should see this output here baseball coach,
14
00:00:52,080 --> 00:00:53,730
cricket coach, tennis coach.
15
00:00:53,730 --> 00:00:56,910
And notice since we're not injecting the track coach
16
00:00:56,910 --> 00:00:59,790
it is not initialized, it's lazy.
17
00:00:59,790 --> 00:01:00,623
That's the person that says,
18
00:01:00,623 --> 00:01:03,240
Hey call me only if you really need me.
19
00:01:03,240 --> 00:01:05,010
If you don't need me I'm not gonna just show up
20
00:01:05,010 --> 00:01:06,363
and do nothing.
21
00:01:07,830 --> 00:01:10,443
All right, great. So that's how lazy works out.
22
00:01:13,740 --> 00:01:16,890
Now let's go ahead and set up lazy initialization
23
00:01:16,890 --> 00:01:21,310
on a global scale or global configuration here
24
00:01:24,720 --> 00:01:29,043
and we can set that up in our application.properties file.
25
00:01:34,170 --> 00:01:37,350
And let me kind of zoom in here for a second
26
00:01:37,350 --> 00:01:39,120
and I'll give the actual property
27
00:01:39,120 --> 00:01:43,093
spring.main.lazy initialization equals true.
28
00:01:49,200 --> 00:01:52,170
And remember that all beans are lazy.
29
00:01:52,170 --> 00:01:53,850
No beans are created until needed
30
00:01:53,850 --> 00:01:55,983
including our demo controller.
31
00:01:57,210 --> 00:01:58,830
Now let's zoom out here and let's go ahead
32
00:01:58,830 --> 00:02:00,830
and run our application and test it out.
33
00:02:06,360 --> 00:02:08,130
And then our application is up and running.
34
00:02:08,130 --> 00:02:11,190
Notice there were no log statements or print line statements
35
00:02:11,190 --> 00:02:14,130
for any of our beans because they weren't constructed yet
36
00:02:14,130 --> 00:02:15,000
or needed.
37
00:02:15,000 --> 00:02:17,820
They're all lazy, including our demo controller.
38
00:02:17,820 --> 00:02:20,250
Now if we go ahead and hit this endpoint
39
00:02:20,250 --> 00:02:22,560
then it's actually gonna reference our demo controller
40
00:02:22,560 --> 00:02:25,260
and also its dependencies accordingly.
41
00:02:25,260 --> 00:02:28,560
So swinging back over here into our IDE
42
00:02:28,560 --> 00:02:30,153
and looking at the logs,
43
00:02:33,930 --> 00:02:37,650
we see that we're in constructor for cricket coach
44
00:02:37,650 --> 00:02:40,200
and also in constructor for demo controller.
45
00:02:40,200 --> 00:02:43,530
So for dependency resolution, spring creates an instance
46
00:02:43,530 --> 00:02:46,650
of the cricket coach first, then it creates an instance
47
00:02:46,650 --> 00:02:50,643
of the demo controller and injects that cricket coach.
48
00:02:51,840 --> 00:02:54,330
Alrighty, so now you kinda see how the lazy initialization
49
00:02:54,330 --> 00:02:56,970
works out and also kinda how spring is doing some
50
00:02:56,970 --> 00:02:58,743
of the work behind the scenes.
51
00:03:01,200 --> 00:03:03,240
All righty, so that's how it all works out.
52
00:03:03,240 --> 00:03:05,430
This looks really good and I'm happy.
53
00:03:05,430 --> 00:03:07,893
I like to say good job my friend.
4264
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.