All language subtitles for 9. Setter Injection - Write Some Code - Part 2

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

Alright, so we're moving right along here. 2

2

So, the next step in our dev process 3

3

is to configure the dependency 4

4

in our Spring configuration file. 5

5

So, let's go ahead and open up our applicationContext.xml 6

6

and we'll set up our dependency injection. 7

7

So, I'll kinda expand the window here for this file 8

8

and I'll move down to the bottom 9

9

and we'll add a new bean entry here for our CricketCoach, 10

10

So, bean ID, myCricketCoach and for the class, equals, 11

11

I'll just kinda leave it empty for right now 12

12

and then I'll come back and use that same technique 13

13

that I used before, 14

14

because I need the fully qualified class name 15

15

of my cricket coach. 16

16

So again, what I'll do is I'll just kinda 17

17

move back to that class CricketCoach 18

18

and I will select it and right click 19

19

and choose, copy qualified name. 20

20

So, that will give me the fully qualified name, 21

21

which the package name dot the class name 22

22

and then I'll move back over to my configuration file, 23

23

and I'll just do a right click and choose paste. 24

24

So there we go. 25

25

So, that's our fully qualified class name for this example. 26

26

Alright, so we're doing pretty good here. 27

27

Now let's go through and actually set up 28

28

our setter injection. 29

29

Set up our setter injection 30

30

and what I'll do here is I'll set up property, 31

31

I'll say name equals and then I'll set ref equals 32

32

and I'll go ahead and fill in some other values here. 33

33

So the name, this is the actual property name here, 34

34

so the property name is fortuneService 35

35

and the ref is gonna be 36

36

the name of myFortuneService 37

37

and again, the ref of myFortuneService, 38

38

that's the bean that was defined a little bit earlier 39

39

in this configuration file, 40

40

I'll kind of scroll up a bit 41

41

so you can see it. 42

42

So, up on line 13 that bean ID of myFortuneService, 43

43

that's the actual same reference 44

44

that we'll use when we inject it into our CricketCoach. 45

45

Okay, great, and then also as a reminder here 46

46

with that property, name equals fortuneService, 47

47

the Spring framework 48

48

will actually call setFortuneService, 49

49

so again, they'll take that property name, 50

50

the first character, they'll make it a cap 51

51

and then they'll call setFortuneService. 52

52

Alright, so we're pretty good here. 53

53

Another thing I wanna do 54

54

is create a new app class for this demo. 55

55

So, just to kinda start from scratch 56

56

just so we have a separate area to work in 57

57

and you know, makes it a little bit simpler 58

58

for us to work through it. 59

59

So, I'll create a new class, 60

60

and I'll call it SetterDemoApp 61

61

and again, just a class that's gonna have a main method 62

62

to read the Spring config 63

63

and perform some operations. 64

64

So, I'll check the box there 65

65

for the main method 66

66

and then I'll keep all the other defaults 67

67

and I'll hit finish. 68

68

Alright, so here's our SetterDemoApp. 69

69

I'll go ahead and clear out this auto-generated stuff 70

70

and I'll just quickly just write some comments here 71

71

as far as what we need to do in this app. 72

72

So again, we're kinda starting from scratch here. 73

73

So, the first thing we'll do is load 74

74

the Spring configuration file. 75

75

We will retrieve the bean from the Spring container. 76

76

Then we'll call methods on the bean of course, 77

77

and then finally we'll be nice 78

78

and we'll close the context. 79

79

So, that's the basic game plan here 80

80

for this demo app, 81

81

and we've seen this before in some previous videos 82

82

but we're just gonna kind of do it again from scratch 83

83

just for this setter example. 84

84

Alrighty here. 85

85

So, loading the Spring configuration file, 86

86

so ClassPathXmlApplicationContext, 87

87

context equals new 88

88

and I use that big long class name, 89

89

I'm just gonna do a copy, paste on that. 90

90

And then I just pass in the actual name of the file 91

91

that I'm reading in, applicationContext.xml, 92

92

so there's my context 93

93

and you can fix the imports here 94

94

by hovering over the red arrow or the red line 95

95

and say import and that'll take care of the imports for you. 96

96

Alright, we're good there. 97

97

Now let's retrieve the bean again 98

98

on the white space at the bottom. 99

99

I'll retrieve the bean by saying CricketCoach, theCoach, 100

100

equals context.getBean 101

101

and I give the name of the bean, myCricketCoach 102

102

comma and then CricketCoach.class. 103

103

Alright, so now when we retrieve this bean, 104

104

they'll actually do all the setter injection work 105

105

behind the scenes for us. 106

106

And then actually this is kinda cool, 107

107

let's do this real quick. 108

108

So, let's do this context.close 109

109

and that line here for calling methods on the bean, 110

110

let's just say that we'll come back and do this later 111

111

because what I wanna do is just check 112

112

the basic operations here, 113

113

what Spring is doing behind the scenes 114

114

because we put some print line methods in there 115

115

as far as the constructor and the setter 116

116

and Spring should call those methods automatically 117

117

and so we should see something 118

118

when we actually run this program. 119

119

So, let's go ahead and save this 120

120

and let's do a right click 121

121

and choose run as Java application 122

122

and we beam up the console 123

123

and oh yeah, looks really good. 124

124

Look at that. 125

125

So, we're loading that config file, 126

126

so it reads the configs, 127

127

and then here it says we're inside the no-arg constructor 128

128

and we're inside the setter method 129

129

and those are those little print line methods 130

130

that we personally added, 131

131

so we know that Spring is actually calling 132

132

these methods for us behind the scenes 133

133

when they're processing that config file, 134

134

so this all kinda works out 135

135

with everything that we've been learning here 136

136

in the video, 137

137

so this looks really good. 138

138

I'm confident now going forward 139

139

with how this part works out. 140

140

Alright, so now we can move back into our SetterDemoApp 141

141

and then we can go ahead and actually write some code 142

142

for doing this stuff. 143

143

So, let's go ahead and call the methods now. 144

144

So, I'm just gonna do a print line on the workout 145

145

and the fortune. 146

146

So, sysout print line. 147

147

Here I'll say theCoach.getDailyFortune, 148

148

I'm sorry, actually getDailyWorkout 149

149

and then a similar thing here for theCoach.getDailyFortune. 150

150

There we go, that's my fortune, alright. 151

151

Alright, good stuff. 152

152

So, these are the methods here 153

153

that we're calling on our coach 154

154

and we should see again, some information being displayed 155

155

to the screen when we run it. 156

156

Alright, so again, we save it, 157

157

right click, run as Java application 158

158

and we look at the console window here 159

159

and oh yeah, looking good. 160

160

So, those are our diagnostic messages up top 161

161

and then that's our daily workout, 162

162

practice fast bowling, 163

163

and then the item here is our fortune, 164

164

today is your lucky day. 165

165

So, this is great, 166

166

so everything kind of works out as desired. 167

167

Spring is making use of setter injection, 168

168

they're injecting that fortune service 169

169

and then we can use our coach 170

170

and call methods just like we could do before 171

171

with all the other coaches like baseball coach 172

172

and track coach, so again, 173

173

really good example here. 174

174

We're just making use of another technique in Spring 175

175

as far doing setter injection. 176

176

So again, great job, pat yourself on the back 177

177

and we're moving.

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