All language subtitles for 4. Spring Inversion of Control - Overview

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese Download
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,130 --> 00:00:02,590 In this video, we're going to cover 2 2 00:00:02,590 --> 00:00:04,833 Spring Inversion of Control. 3 3 00:00:07,410 --> 00:00:09,430 Now in the previous videos, we were working 4 4 00:00:09,430 --> 00:00:11,140 on our application. 5 5 00:00:11,140 --> 00:00:13,523 However, we didn't get it to a hundred percent 6 6 00:00:13,523 --> 00:00:16,910 because we didn't have the support for the configuration. 7 7 00:00:16,910 --> 00:00:19,850 And so we need to make use of an object factory 8 8 00:00:19,850 --> 00:00:22,433 to kind of help us out with this solution. 9 9 00:00:24,170 --> 00:00:26,050 And as I mentioned earlier, this is exactly 10 10 00:00:26,050 --> 00:00:27,820 what Spring comes into play. 11 11 00:00:27,820 --> 00:00:30,960 So Spring provides an object factory so we can have 12 12 00:00:30,960 --> 00:00:34,430 our application talk to Spring, say hey, give me an object. 13 13 00:00:34,430 --> 00:00:37,860 Based on a configuration file or annotation, 14 14 00:00:37,860 --> 00:00:40,840 Spring will give you the appropriate implementation. 15 15 00:00:40,840 --> 00:00:43,270 So then your app is configurable and will have 16 16 00:00:43,270 --> 00:00:46,650 full support for that based on our application requirements. 17 17 00:00:46,650 --> 00:00:47,950 So this looks pretty good. 18 18 00:00:49,590 --> 00:00:51,560 All right, so now we're into some real Spring stuff. 19 19 00:00:51,560 --> 00:00:54,430 So the Spring container, the primary functions 20 20 00:00:54,430 --> 00:00:57,750 of the Spring container is, one, create and manage objects, 21 21 00:00:57,750 --> 00:01:01,170 that's your inversion of control; and then two, 22 22 00:01:01,170 --> 00:01:03,900 inject object's dependencies, and that's what 23 23 00:01:03,900 --> 00:01:06,450 they call dependency injection. 24 24 00:01:06,450 --> 00:01:08,890 Now we'll actually cover all of this in the course. 25 25 00:01:08,890 --> 00:01:11,010 I'll start off with inversion of control, 26 26 00:01:11,010 --> 00:01:12,960 and then the following videos we'll actually get 27 27 00:01:12,960 --> 00:01:15,183 into dependency injection. 28 28 00:01:17,720 --> 00:01:20,430 There's three ways of configuring the Spring container. 29 29 00:01:20,430 --> 00:01:23,140 One is by using an XML configuration file, 30 30 00:01:23,140 --> 00:01:25,490 the other is using Java annotations. 31 31 00:01:25,490 --> 00:01:28,130 And then finally, you can make use of Java source code. 32 32 00:01:28,130 --> 00:01:30,540 And we'll actually cover all of these approaches 33 33 00:01:30,540 --> 00:01:33,220 or all of these techniques in this course. 34 34 00:01:33,220 --> 00:01:35,720 So let's talk about the XML configuration file. 35 35 00:01:35,720 --> 00:01:37,930 It's the original configuration file 36 36 00:01:37,930 --> 00:01:39,750 that was used when Spring was first released, 37 37 00:01:39,750 --> 00:01:42,160 so it's legacy, but we'll still cover it 38 38 00:01:42,160 --> 00:01:44,780 because most legacy apps still use this. 39 39 00:01:44,780 --> 00:01:47,880 So if you're joining a Spring team or you're joining 40 40 00:01:47,880 --> 00:01:50,503 a company that has existing Spring applications, 41 41 00:01:50,503 --> 00:01:54,730 it's a very high likelihood that their applications 42 42 00:01:54,730 --> 00:01:56,590 still use XML config files. 43 43 00:01:56,590 --> 00:01:58,410 So we'll start off with that. 44 44 00:01:58,410 --> 00:02:00,890 Also, Java annotation is kind of like the latest fad, 45 45 00:02:00,890 --> 00:02:03,290 the latest fashion, making annotations. 46 46 00:02:03,290 --> 00:02:05,910 And also, you can actually get rid of all config files 47 47 00:02:05,910 --> 00:02:07,210 and you can configure the container 48 48 00:02:07,210 --> 00:02:09,160 by using Java source code. 49 49 00:02:09,160 --> 00:02:12,160 But again, we're going to cover all of these techniques 50 50 00:02:12,160 --> 00:02:14,410 so you'll understand how each one of them works 51 51 00:02:14,410 --> 00:02:15,743 for your application. 52 52 00:02:18,090 --> 00:02:20,450 All right, so here's the Spring development process. 53 53 00:02:20,450 --> 00:02:21,870 And as you know, I luv to do lists, 54 54 00:02:21,870 --> 00:02:23,250 I luv step-by-step approaches. 55 55 00:02:23,250 --> 00:02:26,710 So the first step is configuring your Spring beans. 56 56 00:02:26,710 --> 00:02:29,940 The second step is creating a Spring container. 57 57 00:02:29,940 --> 00:02:31,840 And then the third step is retrieving 58 58 00:02:31,840 --> 00:02:33,730 the beans from the container. 59 59 00:02:33,730 --> 00:02:36,180 And we'll actually cover all of this step by step 60 60 00:02:36,180 --> 00:02:37,940 so you'll see how everything works, 61 61 00:02:37,940 --> 00:02:39,840 and we'll do all of this from scratch. 62 62 00:02:42,650 --> 00:02:44,040 All right, so let's start with step one, 63 63 00:02:44,040 --> 00:02:45,640 configuring your Spring beans. 64 64 00:02:45,640 --> 00:02:46,887 So in this example, I'm going to make use 65 65 00:02:46,887 --> 00:02:49,540 of the XML configuration file. 66 66 00:02:49,540 --> 00:02:51,160 So here in the XML config file 67 67 00:02:51,160 --> 00:02:54,820 called applicationContext.xml, I have a bean. 68 68 00:02:54,820 --> 00:02:57,690 I give the actual bean id, myCoach, 69 69 00:02:57,690 --> 00:02:58,790 and then I give the class. 70 70 00:02:58,790 --> 00:03:02,140 And that's the fully qualified name of the Java class. 71 71 00:03:02,140 --> 00:03:05,980 So the id, that's simply the id that your Java application 72 72 00:03:05,980 --> 00:03:08,890 will use when they want to retrieve a beam 73 73 00:03:08,890 --> 00:03:10,910 from the Spring container. 74 74 00:03:10,910 --> 00:03:14,150 And again, class is the actual class or implementation 75 75 00:03:14,150 --> 00:03:16,543 that you'll have for your application. 76 76 00:03:21,630 --> 00:03:23,010 Okay, so let's move to step two. 77 77 00:03:23,010 --> 00:03:25,500 So step two is creating a Spring container. 78 78 00:03:25,500 --> 00:03:28,480 So in the Spring world, a Spring container is generally 79 79 00:03:28,480 --> 00:03:31,400 known as an ApplicationContext. 80 80 00:03:31,400 --> 00:03:33,600 So that's the term that you'll see a lot 81 81 00:03:33,600 --> 00:03:36,120 in Spring documentation and in Spring apps. 82 82 00:03:36,120 --> 00:03:38,870 So they have specialized implementations of it, 83 83 00:03:38,870 --> 00:03:41,300 one for reading XML from the class path, 84 84 00:03:41,300 --> 00:03:45,320 an AnnotationConfig, a WebApplicationContext and so on. 85 85 00:03:45,320 --> 00:03:48,073 And we'll take a look at all of these in this course. 86 86 00:03:51,420 --> 00:03:53,130 All righty, so creating the Spring container. 87 87 00:03:53,130 --> 00:03:55,620 So in this example, I'm going to read an XML file 88 88 00:03:55,620 --> 00:03:57,100 that's on my class path. 89 89 00:03:57,100 --> 00:04:01,670 So I make use of this ClassPathXmlApplicationContext. 90 90 00:04:01,670 --> 00:04:04,060 And I construct this object and I pass in 91 91 00:04:04,060 --> 00:04:06,900 the actual name of the configuration file 92 92 00:04:06,900 --> 00:04:08,030 that I'm using for Spring. 93 93 00:04:08,030 --> 00:04:09,420 So from step one, 94 94 00:04:09,420 --> 00:04:12,133 we had a file called applicationContext.xml. 95 95 00:04:14,070 --> 00:04:15,400 You can use any name that you want 96 96 00:04:15,400 --> 00:04:17,910 as long as you're consistent between step one and step two 97 97 00:04:17,910 --> 00:04:20,543 as far as reading that configuration file. 98 98 00:04:21,850 --> 00:04:24,150 All right, so we have this container create it. 99 99 00:04:24,150 --> 00:04:26,290 Now the next step is retrieving the beans 100 100 00:04:26,290 --> 00:04:27,400 from the container. 101 101 00:04:27,400 --> 00:04:29,780 So your application is simply going to talk 102 102 00:04:29,780 --> 00:04:32,240 to the Spring container and say hey, 103 103 00:04:32,240 --> 00:04:34,000 give me a coach object. 104 104 00:04:34,000 --> 00:04:36,690 And based on information in the configuration file, 105 105 00:04:36,690 --> 00:04:41,283 it'll give you an implementation of that given interface. 106 106 00:04:42,470 --> 00:04:44,240 So here's step three as far as code. 107 107 00:04:44,240 --> 00:04:47,320 So the previous line we already created our context, 108 108 00:04:47,320 --> 00:04:50,090 now we retrieve the bean from the container. 109 109 00:04:50,090 --> 00:04:53,920 So here I say context.getBean, 110 110 00:04:53,920 --> 00:04:56,493 and here I say myCoach comma Coach.class. 111 111 00:04:58,410 --> 00:05:01,290 So myCoach relates to the actual bean id 112 112 00:05:01,290 --> 00:05:03,820 to find in the configuration file. 113 113 00:05:03,820 --> 00:05:05,280 You have to make sure those match up 114 114 00:05:05,280 --> 00:05:07,090 with the exact same case. 115 115 00:05:07,090 --> 00:05:10,530 And then Coach.class, that's the name of the actual 116 116 00:05:10,530 --> 00:05:14,370 interface that BaseballCoach implements. 117 117 00:05:14,370 --> 00:05:17,742 So here, Coach.class is the interface, 118 118 00:05:17,742 --> 00:05:20,770 BaseballCoach is the actual implementation. 119 119 00:05:20,770 --> 00:05:21,850 And then you assign it. 120 120 00:05:21,850 --> 00:05:23,210 And that's basically what you have to do 121 121 00:05:23,210 --> 00:05:27,723 for retrieving a bean from a Spring container. 122 122 00:05:30,990 --> 00:05:33,150 All righty, so that's the coding here. 123 123 00:05:33,150 --> 00:05:35,930 In the next video, we're actually going to move into Eclipse. 124 124 00:05:35,930 --> 00:05:38,060 We'll get our hands dirty, and we'll actually write 125 125 00:05:38,060 --> 00:05:39,100 this code and we'll run it, 126 126 00:05:39,100 --> 00:05:41,490 and then we'll actually see it in action. 127 127 00:05:41,490 --> 00:05:42,953 So woohoo! 11247

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.