Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,229 --> 00:00:02,062
Instructor: In this video,
2
00:00:02,062 --> 00:00:04,022
we'll cover Bean Lifecycle Methods.
3
00:00:07,500 --> 00:00:10,560
Here's a high-level view of the bean lifecycle.
4
00:00:10,560 --> 00:00:12,240
When the Spring containers started,
5
00:00:12,240 --> 00:00:15,570
beans are instantiated, dependencies are injected,
6
00:00:15,570 --> 00:00:17,790
internal Spring processing occurs,
7
00:00:17,790 --> 00:00:18,870
and then it can execute
8
00:00:18,870 --> 00:00:21,690
your own custom initialization method.
9
00:00:21,690 --> 00:00:24,330
And then at that point, your bean is ready to use.
10
00:00:24,330 --> 00:00:26,910
And then once the container is shut down or stopped,
11
00:00:26,910 --> 00:00:28,020
then they'll actually make a call
12
00:00:28,020 --> 00:00:29,823
to your custom destroy method.
13
00:00:33,240 --> 00:00:34,140
So what's the purpose
14
00:00:34,140 --> 00:00:36,180
of these bean lifecycle methods or hooks?
15
00:00:36,180 --> 00:00:38,640
Well, this is where you can add your own custom code
16
00:00:38,640 --> 00:00:40,020
during bean initialization.
17
00:00:40,020 --> 00:00:42,630
So calling custom business logic methods,
18
00:00:42,630 --> 00:00:44,100
setting up handles to resources,
19
00:00:44,100 --> 00:00:46,500
like databases, sockets, files.
20
00:00:46,500 --> 00:00:49,320
You can also add custom code during bean destruction.
21
00:00:49,320 --> 00:00:51,810
So again, calling some custom business logic,
22
00:00:51,810 --> 00:00:53,640
or cleaning up handles to any resources
23
00:00:53,640 --> 00:00:56,550
that you may have such as databases, sockets, files,
24
00:00:56,550 --> 00:00:57,383
and so on.
25
00:01:00,390 --> 00:01:02,880
Now, this is how we can set up the method configuration
26
00:01:02,880 --> 00:01:04,650
for an init method.
27
00:01:04,650 --> 00:01:07,260
We have our class here, in this example, CricketCoach,
28
00:01:07,260 --> 00:01:08,093
and then we make use
29
00:01:08,093 --> 00:01:10,260
of this annotation called PostConstruct.
30
00:01:10,260 --> 00:01:11,610
And then we can provide a method here,
31
00:01:11,610 --> 00:01:13,830
in this example, doMyStartupStuff.
32
00:01:13,830 --> 00:01:15,390
You can give it any method name,
33
00:01:15,390 --> 00:01:16,980
but the key here is that this is where you can add
34
00:01:16,980 --> 00:01:19,500
your own custom initialization code
35
00:01:19,500 --> 00:01:21,250
once the bean has been constructed.
36
00:01:24,330 --> 00:01:26,460
And we can do a similar thing here for the destroy method.
37
00:01:26,460 --> 00:01:29,250
So we make use of this annotation here, PreDestroy,
38
00:01:29,250 --> 00:01:30,840
and we have a method, in this case,
39
00:01:30,840 --> 00:01:32,940
public void doMyCleanupStuff.
40
00:01:32,940 --> 00:01:34,800
Again, you can have any method name.
41
00:01:34,800 --> 00:01:37,860
And this allows you to add your own custom logic here
42
00:01:37,860 --> 00:01:39,910
for any cleanup work that you need to do.
43
00:01:42,930 --> 00:01:44,910
Okay, so here's the basic development process.
44
00:01:44,910 --> 00:01:46,410
So you go through and you define your methods
45
00:01:46,410 --> 00:01:47,730
for init and destroy,
46
00:01:47,730 --> 00:01:49,020
and then you add the annotations
47
00:01:49,020 --> 00:01:51,630
for PostConstruct and PreDestroy.
48
00:01:51,630 --> 00:01:52,860
All right, so the next video,
49
00:01:52,860 --> 00:01:53,880
we'll go ahead and write the code
50
00:01:53,880 --> 00:01:55,780
and we'll test out this functionality.
3830
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.