Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,380 --> 00:00:02,969
-: All right, so now we'll move in here
2
00:00:02,969 --> 00:00:05,910
and we'll make use of our alternate solution.
3
00:00:05,910 --> 00:00:09,063
So the first step here is the Create a Configuration class.
4
00:00:13,980 --> 00:00:15,840
And what I'll do is I'll first-off put this
5
00:00:15,840 --> 00:00:17,070
in a separate package,
6
00:00:17,070 --> 00:00:20,220
so I'll create this new package called Config.
7
00:00:20,220 --> 00:00:22,920
So in the spring core demo, I'll have this new package
8
00:00:23,820 --> 00:00:25,563
and it's, dot config.
9
00:00:32,910 --> 00:00:34,350
All right, so I have this config package,
10
00:00:34,350 --> 00:00:35,183
now let's go ahead
11
00:00:35,183 --> 00:00:37,723
and create this new class called SportConfig.
12
00:00:55,209 --> 00:00:56,580
Okay, so we have our Sport Config.
13
00:00:56,580 --> 00:01:00,210
Now it could be in any package, it could be any class name
14
00:01:00,210 --> 00:01:01,980
but I just like to use the word config because,
15
00:01:01,980 --> 00:01:04,230
well, it kinda makes sense, it's a config.
16
00:01:04,230 --> 00:01:06,880
I'll make use of this annotation here, Configuration,
17
00:01:08,430 --> 00:01:10,620
and be sure to choose the annotation Configuration,
18
00:01:10,620 --> 00:01:12,660
not Configurable, okay?
19
00:01:12,660 --> 00:01:14,910
Configuration, as you see here on the screen.
20
00:01:18,810 --> 00:01:21,570
And then we'll cover Step 2 of Defining a Bean method
21
00:01:21,570 --> 00:01:23,073
to configure the bean.
22
00:01:28,110 --> 00:01:29,980
I'll make use of this Bean annotation
23
00:01:32,640 --> 00:01:36,750
and I'll create this method, public Coach, swimCoach.
24
00:01:36,750 --> 00:01:39,927
It's gonna return an instance of a SwimCoach,
25
00:01:41,580 --> 00:01:43,197
so, new SwimCoach.
26
00:01:46,740 --> 00:01:49,260
And we're manually handling the construction here
27
00:01:49,260 --> 00:01:50,493
for this given coach.
28
00:01:52,950 --> 00:01:56,010
And then remember, the bean id defaults to the method name,
29
00:01:56,010 --> 00:01:58,210
so the bean id in this example is swimCoach,
30
00:01:59,310 --> 00:02:00,753
with a lowercase s.
31
00:02:02,340 --> 00:02:03,173
And we can use that
32
00:02:03,173 --> 00:02:05,463
when we inject it into our controller.
33
00:02:06,930 --> 00:02:09,333
Alrighty, so kind of zooming out here for a bit,
34
00:02:11,280 --> 00:02:13,230
and we're okay now, we can go ahead
35
00:02:13,230 --> 00:02:14,763
and run this application.
36
00:02:17,430 --> 00:02:18,840
And then, success!
37
00:02:18,840 --> 00:02:20,910
Notice here, our diagnostics printed out,
38
00:02:20,910 --> 00:02:22,380
In constructor for SwimCoach,
39
00:02:22,380 --> 00:02:24,870
so hey, it's actually creating in a swim coach
40
00:02:24,870 --> 00:02:26,280
and making it available
41
00:02:26,280 --> 00:02:28,080
and the application started up successfully
42
00:02:28,080 --> 00:02:29,160
so nothing failed.
43
00:02:29,160 --> 00:02:30,180
So this is also good.
44
00:02:30,180 --> 00:02:33,333
So that SwimCoach was injected into our Controller.
45
00:02:37,920 --> 00:02:39,660
And then we can verify this by swinging
46
00:02:39,660 --> 00:02:41,970
over to our web browser and then going
47
00:02:41,970 --> 00:02:46,273
to localhost:8080/daily workout,
48
00:02:50,610 --> 00:02:53,550
and "Swim 1000 meters as a warm up".
49
00:02:53,550 --> 00:02:56,310
So that comes from our actual swim coach,
50
00:02:56,310 --> 00:02:57,840
based on its configuration.
51
00:02:57,840 --> 00:03:02,160
So, remember SwimCoach did not have the Component annotation
52
00:03:02,160 --> 00:03:04,470
and it failed the first time we ran it.
53
00:03:04,470 --> 00:03:06,900
And then we simply configured this as a Spring bean
54
00:03:06,900 --> 00:03:09,120
using the Bean annotation,
55
00:03:09,120 --> 00:03:11,250
and then everything worked out for us.
56
00:03:11,250 --> 00:03:13,560
All right, so this is more of a contrived example,
57
00:03:13,560 --> 00:03:16,500
but from that real world example I gave you a little earlier
58
00:03:16,500 --> 00:03:18,510
the whole idea of making use of the Bean annotation is
59
00:03:18,510 --> 00:03:21,390
to take an existing third-party class
60
00:03:21,390 --> 00:03:23,910
and then wrap it and expose it as a bean
61
00:03:23,910 --> 00:03:26,373
that we can use in our Spring applications.
62
00:03:31,230 --> 00:03:32,220
All right, so I'm not done.
63
00:03:32,220 --> 00:03:34,920
Let's play around with one more thing here.
64
00:03:34,920 --> 00:03:36,660
Let's swing back into our code
65
00:03:36,660 --> 00:03:38,520
and now let's give our bean a custom id,
66
00:03:38,520 --> 00:03:40,980
so instead of using whatever the method name is,
67
00:03:40,980 --> 00:03:43,530
let's give it a custom Bean id, and we can do that
68
00:03:43,530 --> 00:03:47,190
by simply providing a string here for this bean annotation
69
00:03:47,190 --> 00:03:49,200
and I'll call this bean, aquatic.
70
00:03:49,200 --> 00:03:51,003
Just making something up here.
71
00:03:52,320 --> 00:03:54,600
So that's the bean id that we can use.
72
00:03:54,600 --> 00:03:57,240
We can swing back over into our controller
73
00:03:57,240 --> 00:04:00,450
and then we can inject that given bean id.
74
00:04:00,450 --> 00:04:03,663
So we make use of our custom bean id of, aquatic.
75
00:04:12,390 --> 00:04:15,290
All righty, everything should kind of reload there for us.
76
00:04:16,560 --> 00:04:18,390
And now if I swing back over to my browser
77
00:04:18,390 --> 00:04:21,420
and do a reload, then everything still works as desired.
78
00:04:21,420 --> 00:04:23,430
So we're still injecting that swim coach
79
00:04:23,430 --> 00:04:24,810
and we can still make use of them.
80
00:04:24,810 --> 00:04:26,760
So, this is great. I'm happy.
81
00:04:26,760 --> 00:04:27,593
I like it.
6321
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.