Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
1
00:00:01,170 --> 00:00:02,120
In this video,
2
2
00:00:02,120 --> 00:00:04,880
we're gonna discuss bean lifecycle methods.
3
3
00:00:07,790 --> 00:00:10,140
So when the Spring container first starts
4
4
00:00:10,140 --> 00:00:12,240
there are a couple of things that happens.
5
5
00:00:13,610 --> 00:00:16,720
First off, the beans are instantiated,
6
6
00:00:16,720 --> 00:00:19,410
and then the actual dependencies are injected,
7
7
00:00:21,650 --> 00:00:24,180
next you have some internal Spring processing
8
8
00:00:24,180 --> 00:00:26,080
that occurs with the bean factory,
9
9
00:00:26,980 --> 00:00:28,230
and then you have the option
10
10
00:00:28,230 --> 00:00:31,670
of adding your own custom initialization code,
11
11
00:00:33,460 --> 00:00:35,880
and then at that point the bean is ready for use.
12
12
00:00:35,880 --> 00:00:37,360
So you can call methods on it,
13
13
00:00:37,360 --> 00:00:38,460
do work with the bean,
14
14
00:00:38,460 --> 00:00:39,960
so on and so forth.
15
15
00:00:39,960 --> 00:00:42,330
At a certain point the containers actually shutdown
16
16
00:00:42,330 --> 00:00:44,230
meaning your application is shutdown
17
17
00:00:44,230 --> 00:00:46,340
like what context.close,
18
18
00:00:46,340 --> 00:00:47,880
then you also have a chance
19
19
00:00:47,880 --> 00:00:50,190
to call your custom destroy method,
20
20
00:00:50,190 --> 00:00:53,350
and that code'll execute before the actual application
21
21
00:00:53,350 --> 00:00:57,500
is stopped or before the actual beans lifecycle is over.
22
22
00:00:58,350 --> 00:00:59,500
The one thing you want to take a look
23
23
00:00:59,500 --> 00:01:01,190
at are those two orange sections
24
24
00:01:01,190 --> 00:01:04,410
here adding your own custom methods.
25
25
00:01:06,140 --> 00:01:08,890
What you can do is you can add your own custom code
26
26
00:01:08,890 --> 00:01:12,260
that happens during bean initialization.
27
27
00:01:12,260 --> 00:01:14,300
So you can call custom business logic,
28
28
00:01:14,300 --> 00:01:15,330
you can set up handles,
29
29
00:01:15,330 --> 00:01:18,590
so like databases, or sockets, or whatever.
30
30
00:01:18,590 --> 00:01:20,250
You can also do a similar thing
31
31
00:01:20,250 --> 00:01:23,190
when a bean is actually being destroyed or destructed.
32
32
00:01:23,190 --> 00:01:25,795
So again, you can call any custom business methods,
33
33
00:01:25,795 --> 00:01:28,860
or you can clean up any handles
34
34
00:01:28,860 --> 00:01:30,240
that you may have to resources
35
35
00:01:30,240 --> 00:01:32,370
like databases, sockets, or files.
36
36
00:01:32,370 --> 00:01:34,610
So basically what this provides here
37
37
00:01:34,610 --> 00:01:36,900
is that during the bean lifecycle,
38
38
00:01:36,900 --> 00:01:40,340
Spring allows you to call some of your custom code,
39
39
00:01:40,340 --> 00:01:41,920
and these are what we call hooks,
40
40
00:01:41,920 --> 00:01:43,390
where you can actually hook in codes
41
41
00:01:43,390 --> 00:01:47,810
to execute during bean initialization or bean destruction.
42
42
00:01:50,350 --> 00:01:52,160
All right, so now, how would you do this?
43
43
00:01:52,160 --> 00:01:55,650
Well, you simply make configuration entry in your XML file.
44
44
00:01:55,650 --> 00:01:57,880
So for bean initialization,
45
45
00:01:57,880 --> 00:02:01,260
you make use of this attribute called init-method,
46
46
00:02:01,260 --> 00:02:03,690
and then you give the actual method name
47
47
00:02:03,690 --> 00:02:06,150
that you would like for Spring to call on your bean.
48
48
00:02:06,150 --> 00:02:09,310
Now this method name can be any method name.
49
49
00:02:09,310 --> 00:02:11,040
Here I called doMyStartupStuff.
50
50
00:02:11,040 --> 00:02:13,190
It could be called fubar or whatever,
51
51
00:02:16,970 --> 00:02:20,200
and we can also do a similar thing for the destroy method.
52
52
00:02:20,200 --> 00:02:21,490
So again, you simply make
53
53
00:02:21,490 --> 00:02:24,160
a configuration entry here in your XML file.
54
54
00:02:24,160 --> 00:02:25,580
You simply give the method name
55
55
00:02:25,580 --> 00:02:27,510
you want Spring to call for destroy,
56
56
00:02:27,510 --> 00:02:29,140
and again, it can be any name.
57
57
00:02:31,520 --> 00:02:33,000
All right, so this all looks kinda good.
58
58
00:02:33,000 --> 00:02:34,640
What's the basic development process?
59
59
00:02:34,640 --> 00:02:36,830
So again, I love my step-by-step.
60
60
00:02:36,830 --> 00:02:38,340
So the first thing you do is you simply
61
61
00:02:38,340 --> 00:02:40,720
define your methods for the init and destroy
62
62
00:02:40,720 --> 00:02:43,380
in your bean class, then the next step
63
63
00:02:43,380 --> 00:02:45,229
is you simply configure those method names
64
64
00:02:45,229 --> 00:02:47,630
in the Spring configuration file,
65
65
00:02:47,630 --> 00:02:50,740
and in the next video, we'll dive into Eclipse,
66
66
00:02:50,740 --> 00:02:52,784
and we'll actually walk through this development process,
67
67
00:02:52,784 --> 00:02:54,910
and we'll test out this feature.
68
68
00:02:54,910 --> 00:02:56,780
So I'll see you in the next video.
5834
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.