Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
In this video, we're going to cover 2
2
Spring Inversion of Control. 3
3
Now in the previous videos, we were working 4
4
on our application. 5
5
However, we didn't get it to a hundred percent 6
6
because we didn't have the support for the configuration. 7
7
And so we need to make use of an object factory 8
8
to kind of help us out with this solution. 9
9
And as I mentioned earlier, this is exactly 10
10
what Spring comes into play. 11
11
So Spring provides an object factory so we can have 12
12
our application talk to Spring, say hey, give me an object. 13
13
Based on a configuration file or annotation, 14
14
Spring will give you the appropriate implementation. 15
15
So then your app is configurable and will have 16
16
full support for that based on our application requirements. 17
17
So this looks pretty good. 18
18
All right, so now we're into some real Spring stuff. 19
19
So the Spring container, the primary functions 20
20
of the Spring container is, one, create and manage objects, 21
21
that's your inversion of control; and then two, 22
22
inject object's dependencies, and that's what 23
23
they call dependency injection. 24
24
Now we'll actually cover all of this in the course. 25
25
I'll start off with inversion of control, 26
26
and then the following videos we'll actually get 27
27
into dependency injection. 28
28
There's three ways of configuring the Spring container. 29
29
One is by using an XML configuration file, 30
30
the other is using Java annotations. 31
31
And then finally, you can make use of Java source code. 32
32
And we'll actually cover all of these approaches 33
33
or all of these techniques in this course. 34
34
So let's talk about the XML configuration file. 35
35
It's the original configuration file 36
36
that was used when Spring was first released, 37
37
so it's legacy, but we'll still cover it 38
38
because most legacy apps still use this. 39
39
So if you're joining a Spring team or you're joining 40
40
a company that has existing Spring applications, 41
41
it's a very high likelihood that their applications 42
42
still use XML config files. 43
43
So we'll start off with that. 44
44
Also, Java annotation is kind of like the latest fad, 45
45
the latest fashion, making annotations. 46
46
And also, you can actually get rid of all config files 47
47
and you can configure the container 48
48
by using Java source code. 49
49
But again, we're going to cover all of these techniques 50
50
so you'll understand how each one of them works 51
51
for your application. 52
52
All right, so here's the Spring development process. 53
53
And as you know, I luv to do lists, 54
54
I luv step-by-step approaches. 55
55
So the first step is configuring your Spring beans. 56
56
The second step is creating a Spring container. 57
57
And then the third step is retrieving 58
58
the beans from the container. 59
59
And we'll actually cover all of this step by step 60
60
so you'll see how everything works, 61
61
and we'll do all of this from scratch. 62
62
All right, so let's start with step one, 63
63
configuring your Spring beans. 64
64
So in this example, I'm going to make use 65
65
of the XML configuration file. 66
66
So here in the XML config file 67
67
called applicationContext.xml, I have a bean. 68
68
I give the actual bean id, myCoach, 69
69
and then I give the class. 70
70
And that's the fully qualified name of the Java class. 71
71
So the id, that's simply the id that your Java application 72
72
will use when they want to retrieve a beam 73
73
from the Spring container. 74
74
And again, class is the actual class or implementation 75
75
that you'll have for your application. 76
76
Okay, so let's move to step two. 77
77
So step two is creating a Spring container. 78
78
So in the Spring world, a Spring container is generally 79
79
known as an ApplicationContext. 80
80
So that's the term that you'll see a lot 81
81
in Spring documentation and in Spring apps. 82
82
So they have specialized implementations of it, 83
83
one for reading XML from the class path, 84
84
an AnnotationConfig, a WebApplicationContext and so on. 85
85
And we'll take a look at all of these in this course. 86
86
All righty, so creating the Spring container. 87
87
So in this example, I'm going to read an XML file 88
88
that's on my class path. 89
89
So I make use of this ClassPathXmlApplicationContext. 90
90
And I construct this object and I pass in 91
91
the actual name of the configuration file 92
92
that I'm using for Spring. 93
93
So from step one, 94
94
we had a file called applicationContext.xml. 95
95
You can use any name that you want 96
96
as long as you're consistent between step one and step two 97
97
as far as reading that configuration file. 98
98
All right, so we have this container create it. 99
99
Now the next step is retrieving the beans 100
100
from the container. 101
101
So your application is simply going to talk 102
102
to the Spring container and say hey, 103
103
give me a coach object. 104
104
And based on information in the configuration file, 105
105
it'll give you an implementation of that given interface. 106
106
So here's step three as far as code. 107
107
So the previous line we already created our context, 108
108
now we retrieve the bean from the container. 109
109
So here I say context.getBean, 110
110
and here I say myCoach comma Coach.class. 111
111
So myCoach relates to the actual bean id 112
112
to find in the configuration file. 113
113
You have to make sure those match up 114
114
with the exact same case. 115
115
And then Coach.class, that's the name of the actual 116
116
interface that BaseballCoach implements. 117
117
So here, Coach.class is the interface, 118
118
BaseballCoach is the actual implementation. 119
119
And then you assign it. 120
120
And that's basically what you have to do 121
121
for retrieving a bean from a Spring container. 122
122
All righty, so that's the coding here. 123
123
In the next video, we're actually going to move into Eclipse. 124
124
We'll get our hands dirty, and we'll actually write 125
125
this code and we'll run it, 126
126
and then we'll actually see it in action. 127
127
So woohoo!
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.