Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,350 --> 00:00:02,490
Instructor: All righty, let's get started.
2
00:00:02,490 --> 00:00:04,540
So we'll do our normal housekeeping work.
3
00:00:19,110 --> 00:00:20,850
And let's move in here to our file system
4
00:00:20,850 --> 00:00:24,390
and we'll copy this directory, 07-bean-scopes,
5
00:00:24,390 --> 00:00:26,790
and we'll paste it and we'll give it a new name.
6
00:00:30,930 --> 00:00:34,833
And the new name we'll give it is 08-bean-lifecycle-methods.
7
00:00:38,310 --> 00:00:41,013
And let's go ahead and open this project in IntelliJ.
8
00:00:56,280 --> 00:00:58,770
And one thing I'd like to do here is just some cleanup work.
9
00:00:58,770 --> 00:01:02,490
I'd like to change the code to inject only one coach
10
00:01:02,490 --> 00:01:03,960
and to use singleton scope.
11
00:01:03,960 --> 00:01:05,850
Just want to kind of keep it simple.
12
00:01:05,850 --> 00:01:08,523
Give me some good baseline code to work with.
13
00:01:19,943 --> 00:01:22,530
I'll move into the DemoController,
14
00:01:22,530 --> 00:01:24,573
expand my window here for a second,
15
00:01:28,020 --> 00:01:29,790
and I'll remove one of the coaches here.
16
00:01:29,790 --> 00:01:32,133
So I'll remove this anotherCoach field.
17
00:01:36,000 --> 00:01:36,837
And then I'll also move down here
18
00:01:36,837 --> 00:01:41,327
and remove the qualifier for theAnotherCoach.
19
00:01:43,290 --> 00:01:44,883
And fix the curly brace here.
20
00:01:46,800 --> 00:01:48,783
Remove this line with the assignment.
21
00:01:50,010 --> 00:01:52,320
And so this is kind of what my constructor should look like
22
00:01:52,320 --> 00:01:54,063
for the DemoController.
23
00:01:58,920 --> 00:02:00,660
And then this GetMapping for check,
24
00:02:00,660 --> 00:02:03,260
we'll go ahead and delete this section of code also.
25
00:02:09,479 --> 00:02:11,910
All right, so this is basically what our application
26
00:02:11,910 --> 00:02:13,800
should look like or our coach should look like
27
00:02:13,800 --> 00:02:14,853
at this point.
28
00:02:21,660 --> 00:02:22,980
And then I'd also like to go over
29
00:02:22,980 --> 00:02:24,810
and make the change here to CricketCoach.
30
00:02:24,810 --> 00:02:29,220
And so I want to remove the prototype scope.
31
00:02:29,220 --> 00:02:31,833
So I'll just delete this Scope annotation here.
32
00:02:44,490 --> 00:02:46,413
All righty. So this looks pretty good.
33
00:02:55,530 --> 00:02:57,300
And then we can kind of get down to business here.
34
00:02:57,300 --> 00:03:00,600
So step one of defining the methods for init and destroy,
35
00:03:00,600 --> 00:03:02,280
and then adding the annotations here
36
00:03:02,280 --> 00:03:04,593
for @PostConstruct and @PreDestroy.
37
00:03:07,920 --> 00:03:09,660
I'll just write some quick comments here to myself
38
00:03:09,660 --> 00:03:11,583
just to kind of keep myself on track.
39
00:03:22,960 --> 00:03:24,930
Okay, this is our basic game plan here
40
00:03:24,930 --> 00:03:26,040
defining our init method
41
00:03:26,040 --> 00:03:27,963
and also defining our destroy method.
42
00:03:28,890 --> 00:03:31,140
So I'll start here with the init method
43
00:03:31,140 --> 00:03:33,753
and I'll make use of the annotation PostConstruct.
44
00:03:40,590 --> 00:03:42,660
I give a method here, doMyStartupStuff.
45
00:03:42,660 --> 00:03:45,360
Again, you can use any method name here that you want.
46
00:03:48,690 --> 00:03:50,640
And then I'll just do a little print line statement here
47
00:03:50,640 --> 00:03:52,050
just to let them know that hey,
48
00:03:52,050 --> 00:03:55,173
we're in doStartupStuff for a given class.
49
00:04:15,750 --> 00:04:18,329
Alrighty, this looks pretty good for our PostConstruct.
50
00:04:18,329 --> 00:04:20,100
So this is our init method.
51
00:04:20,100 --> 00:04:21,600
Let's kind of copy-paste this
52
00:04:21,600 --> 00:04:24,333
and let's do a similar thing here for PreDestroy.
53
00:04:26,160 --> 00:04:27,090
So I'll just paste it.
54
00:04:27,090 --> 00:04:29,570
I'll update the annotation PreDestroy.
55
00:04:37,524 --> 00:04:38,520
And then I'll just move down here
56
00:04:38,520 --> 00:04:42,303
and just give it a new method name, doMyCleanupStuff.
57
00:04:44,970 --> 00:04:46,970
Let's update our print line accordingly.
58
00:04:51,540 --> 00:04:54,570
And that's the coding there for our destroy method.
59
00:04:54,570 --> 00:04:55,820
It looks good. I like it.
60
00:05:00,450 --> 00:05:02,160
Now let's go ahead and test this out.
61
00:05:02,160 --> 00:05:03,843
Let's just run our application.
62
00:05:10,860 --> 00:05:12,510
Our app is up and running.
63
00:05:12,510 --> 00:05:14,340
And one thing to notice here,
64
00:05:14,340 --> 00:05:17,460
we see the code or the execution of our init method here.
65
00:05:17,460 --> 00:05:20,130
So in doMyStartupStuff for CricketCoach.
66
00:05:20,130 --> 00:05:21,840
So notice the previous line,
67
00:05:21,840 --> 00:05:23,670
we're in the constructor for CricketCoach
68
00:05:23,670 --> 00:05:26,220
and then we have our custom init method that runs
69
00:05:26,220 --> 00:05:27,630
as a PostConstruct.
70
00:05:27,630 --> 00:05:29,030
So this is great. I like it.
71
00:05:34,560 --> 00:05:37,020
Now if I stop the application,
72
00:05:37,020 --> 00:05:40,680
then we should execute our PreDestroy method.
73
00:05:40,680 --> 00:05:42,510
So we're gonna just stop, scroll down a bit,
74
00:05:42,510 --> 00:05:45,120
and then we'll see that this print line here
75
00:05:45,120 --> 00:05:47,340
in doMyCleanupStuff.
76
00:05:47,340 --> 00:05:50,460
So this code is actually executing as desired.
77
00:05:50,460 --> 00:05:52,080
So this was great. I like it.
78
00:05:52,080 --> 00:05:52,913
Good job.
6109
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.