All language subtitles for 5. Spring Dependency Injection - Write Some Code - Part 3

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
vi Vietnamese Download
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,474 --> 00:00:02,767 Wow, we did some great stuff 2 2 00:00:02,767 --> 00:00:05,221 in that last video so we're pretty much taken care of. 3 3 00:00:05,221 --> 00:00:08,819 We've covered steps one, steps two and step three, 4 4 00:00:08,819 --> 00:00:10,423 so we're ready to go. 5 5 00:00:10,423 --> 00:00:11,330 So, what we're gonna do now 6 6 00:00:11,330 --> 00:00:15,903 is actually move into our main application class. 7 7 00:00:15,903 --> 00:00:18,230 We'll make use of the beans from Spring 8 8 00:00:18,230 --> 00:00:19,608 and then call some methods on it. 9 9 00:00:19,608 --> 00:00:22,191 So, let's go ahead and dive in. 10 10 00:00:24,483 --> 00:00:25,468 Alright, so let's go ahead 11 11 00:00:25,468 --> 00:00:27,419 and move back to our main application class, 12 12 00:00:27,419 --> 00:00:29,353 our HelloSpringApp, 13 13 00:00:29,353 --> 00:00:31,360 and this is basically everything from before, 14 14 00:00:31,360 --> 00:00:32,894 so we go through it and retrieve the bean 15 15 00:00:32,894 --> 00:00:34,382 from the container myCoach 16 16 00:00:34,382 --> 00:00:38,382 but now this bean actually has some dependencies, right? 17 17 00:00:38,382 --> 00:00:40,403 The dependency meaning the FortuneService, 18 18 00:00:40,403 --> 00:00:44,417 so it actually injects that FortuneService 19 19 00:00:44,417 --> 00:00:46,903 onto that bean, so when we get the bean, 20 20 00:00:46,903 --> 00:00:50,438 we actually get the bean fully assembled. 21 21 00:00:50,438 --> 00:00:54,019 Remember, the Spring factory, they're actually gonna create 22 22 00:00:54,019 --> 00:00:56,898 all the appropriate beans and dependencies 23 23 00:00:56,898 --> 00:00:59,396 and inject those dependencies 24 24 00:00:59,396 --> 00:01:00,904 so you can make use of them, 25 25 00:01:00,904 --> 00:01:03,656 so you'll get a object that's fully assembled, 26 26 00:01:03,656 --> 00:01:06,402 ready to go, so your car has already been built, 27 27 00:01:06,402 --> 00:01:10,171 you simply drive it off the showroom floor. 28 28 00:01:10,171 --> 00:01:11,240 Now that that's taken care of, 29 29 00:01:11,240 --> 00:01:13,202 we simply call methods on the bean 30 30 00:01:13,202 --> 00:01:15,706 and let's go ahead and call the new methods 31 31 00:01:15,706 --> 00:01:19,456 that we actually have for our FortuneService. 32 32 00:01:21,669 --> 00:01:25,197 So, here I just simply do system out print line, 33 33 00:01:25,197 --> 00:01:28,114 and I say theCoach.getDailyFortune. 34 34 00:01:31,710 --> 00:01:34,122 Fortune, nice, I like that. 35 35 00:01:34,122 --> 00:01:34,955 And that's really it. 36 36 00:01:34,955 --> 00:01:37,151 We simply added a new method to support 37 37 00:01:37,151 --> 00:01:39,986 the new functionality that we just added 38 38 00:01:39,986 --> 00:01:42,128 to this application. 39 39 00:01:42,128 --> 00:01:43,199 So, that's cool. 40 40 00:01:43,199 --> 00:01:45,654 Everything else in this app stays the same. 41 41 00:01:45,654 --> 00:01:48,568 There's no major changes here. 42 42 00:01:48,568 --> 00:01:49,839 Alright, let's go ahead and run it. 43 43 00:01:49,839 --> 00:01:52,922 Right click, run as Java application. 44 44 00:01:55,041 --> 00:01:57,374 And voila, this looks great. 45 45 00:01:59,081 --> 00:02:00,709 So, we got our daily workout 46 46 00:02:00,709 --> 00:02:03,496 but now note this item here, 47 47 00:02:03,496 --> 00:02:05,944 today is your lucky day. 48 48 00:02:05,944 --> 00:02:08,084 This is awesome because you're lucky today 49 49 00:02:08,084 --> 00:02:09,597 because you have a Spring app 50 50 00:02:09,597 --> 00:02:13,611 that's actually running using dependency injection 51 51 00:02:13,611 --> 00:02:16,709 and IoC and all those other fancy buzzwords, 52 52 00:02:16,709 --> 00:02:20,044 so you're ready to hang out with your buddies and brag. 53 53 00:02:20,044 --> 00:02:21,854 But anyway, this is cool. 54 54 00:02:21,854 --> 00:02:22,925 I'm having so much fun here. 55 55 00:02:22,925 --> 00:02:24,462 So, we got this working, it's running 56 56 00:02:24,462 --> 00:02:27,112 and we went through all of the whole process 57 57 00:02:27,112 --> 00:02:30,945 step by step, so I'm pretty excited right now. 58 58 00:02:32,789 --> 00:02:34,032 Now let's go back in here 59 59 00:02:34,032 --> 00:02:35,897 and let's make some changes. 60 60 00:02:35,897 --> 00:02:38,454 Let's go ahead and drop in our TrackCoach, 61 61 00:02:38,454 --> 00:02:41,950 so our TrackCoach can also make use of the FortuneService 62 62 00:02:41,950 --> 00:02:45,099 'cause hey, we don't wanna leave anyone out, right? 63 63 00:02:45,099 --> 00:02:46,520 So, we're gonna give equal preference 64 64 00:02:46,520 --> 00:02:50,042 to all of the sports at our university. 65 65 00:02:50,042 --> 00:02:53,710 So, here we have our private FortuneService, 66 66 00:02:53,710 --> 00:02:55,668 service, FortuneService here, 67 67 00:02:55,668 --> 00:02:56,859 so that's for TrackCoach. 68 68 00:02:56,859 --> 00:03:00,319 Our TrackCoach also needs a constructor 69 69 00:03:00,319 --> 00:03:02,114 to support constructor injection. 70 70 00:03:02,114 --> 00:03:03,976 I'm gonna show you a nice little trick. 71 71 00:03:03,976 --> 00:03:07,649 So, right click, go to source, K, one more time, 72 72 00:03:07,649 --> 00:03:09,768 right click, source and choose 73 73 00:03:09,768 --> 00:03:13,815 generate constructor using fields, whoa. 74 74 00:03:13,815 --> 00:03:14,982 So, with that. 75 75 00:03:17,438 --> 00:03:19,584 So, Eclipse will actually look at the fields 76 76 00:03:19,584 --> 00:03:21,583 that you have in your class 77 77 00:03:21,583 --> 00:03:23,721 and it'll actually create a constructor 78 78 00:03:23,721 --> 00:03:25,343 using those fields, 79 79 00:03:25,343 --> 00:03:28,106 so here we have this one field called FortuneService 80 80 00:03:28,106 --> 00:03:30,947 and we can keep all the other defaults 81 81 00:03:30,947 --> 00:03:32,265 and then we can actually move down 82 82 00:03:32,265 --> 00:03:34,817 and hit the OK button 83 83 00:03:34,817 --> 00:03:38,687 and Eclipse will actually generate some code for us. 84 84 00:03:38,687 --> 00:03:40,125 Boo, booya. 85 85 00:03:40,125 --> 00:03:42,999 So, what we see right here on lines seven through nine, 86 86 00:03:42,999 --> 00:03:46,055 this is a constructor that Eclipse created 87 87 00:03:46,055 --> 00:03:47,628 and it created it based on the fields 88 88 00:03:47,628 --> 00:03:48,679 that we have this class. 89 89 00:03:48,679 --> 00:03:50,532 Really cool, I like this feature. 90 90 00:03:50,532 --> 00:03:51,415 And it's very flexible, 91 91 00:03:51,415 --> 00:03:54,705 you can turn it on and off if you have multiple fields, 92 92 00:03:54,705 --> 00:03:56,498 but anyway, that covers it for right now. 93 93 00:03:56,498 --> 00:03:59,274 So, we have our constructor set up for injection, 94 94 00:03:59,274 --> 00:04:00,413 now in the bottom here 95 95 00:04:00,413 --> 00:04:02,284 we're actually gonna use this service, 96 96 00:04:02,284 --> 00:04:04,010 so again, getDailyFortune, 97 97 00:04:04,010 --> 00:04:06,927 we'll say fortuneService.getFortune 98 98 00:04:08,822 --> 00:04:09,940 and for this TrackCoach 99 99 00:04:09,940 --> 00:04:12,159 they're gonna use something a little fancy here. 100 100 00:04:12,159 --> 00:04:12,992 They're gonna add 101 101 00:04:12,992 --> 00:04:15,156 their own little message on the beginning. 102 102 00:04:15,156 --> 00:04:16,073 Just do it. 103 103 00:04:18,243 --> 00:04:20,542 Famous commercial, 104 104 00:04:20,542 --> 00:04:23,030 just do it and then they'll drop in a fortuneService, 105 105 00:04:23,030 --> 00:04:25,093 just a little custom implementation 106 106 00:04:25,093 --> 00:04:26,539 just so that we know the TrackCoach 107 107 00:04:26,539 --> 00:04:28,916 is really doing something differently 108 108 00:04:28,916 --> 00:04:31,271 than you know, the BaseballCoach. 109 109 00:04:31,271 --> 00:04:33,861 Alright, so we have that saved. 110 110 00:04:33,861 --> 00:04:38,363 Now in our config file we just swap out BaseballCoach 111 111 00:04:38,363 --> 00:04:40,780 and we'll drop in TrackCoach. 112 112 00:04:42,648 --> 00:04:44,981 And we'll save that, hit OK. 113 113 00:05:01,166 --> 00:05:02,965 Alright, so let's go ahead and right click and run it, 114 114 00:05:02,965 --> 00:05:05,088 so right click, run as Java application, 115 115 00:05:05,088 --> 00:05:09,401 and oh my gosh, an error exists in the project. 116 116 00:05:09,401 --> 00:05:11,151 Yikes, what happened? 117 117 00:05:12,034 --> 00:05:14,486 MyApp, what's up with that? 118 118 00:05:14,486 --> 00:05:16,013 Oh, got you. 119 119 00:05:16,013 --> 00:05:19,763 This is our old rough prototype from earlier. 120 120 00:05:20,844 --> 00:05:22,444 For know let's comment it out. 121 121 00:05:22,444 --> 00:05:24,137 I'll come back and fix it later 122 122 00:05:24,137 --> 00:05:26,424 but just for now I don't wanna deal with it for right now, 123 123 00:05:26,424 --> 00:05:28,356 so I just hit some comments there, 124 124 00:05:28,356 --> 00:05:31,612 save it and now I'll go back and run it. 125 125 00:05:31,612 --> 00:05:33,439 I'll fix that later, so, 126 126 00:05:33,439 --> 00:05:35,598 and I'll actually fix it in this video, 127 127 00:05:35,598 --> 00:05:39,739 so right click, run as, Java application. 128 128 00:05:39,739 --> 00:05:41,358 Don't want to steal my thunder here 129 129 00:05:41,358 --> 00:05:44,869 because I'm on a role, run a hard 5 K from the TrackCoach 130 130 00:05:44,869 --> 00:05:48,820 and boom, just do it, today is your lucky day. 131 131 00:05:48,820 --> 00:05:53,238 Cool, so our TrackCoach is also serving up fortunes 132 132 00:05:53,238 --> 00:05:55,321 which is really cool, so. 133 133 00:05:57,982 --> 00:05:58,815 I'm happy. 134 134 00:05:59,944 --> 00:06:01,096 And I'm speechless. 135 135 00:06:01,096 --> 00:06:01,929 Yikes. 136 136 00:06:04,049 --> 00:06:06,494 Alright, so let's go back and fix that issue 137 137 00:06:06,494 --> 00:06:09,081 that we had before, set up MyApp. 138 138 00:06:09,081 --> 00:06:11,023 So, we just comment it out with some code 139 139 00:06:11,023 --> 00:06:12,407 but you know, how should we really, 140 140 00:06:12,407 --> 00:06:14,711 what's the real solution here? 141 141 00:06:14,711 --> 00:06:17,127 And the real solution is that over on the left-hand side 142 142 00:06:17,127 --> 00:06:19,303 they're trying to create a TrackCoach 143 143 00:06:19,303 --> 00:06:21,260 but we don't have a no-arg constructor 144 144 00:06:21,260 --> 00:06:23,530 or we don't have a default constructor, 145 145 00:06:23,530 --> 00:06:26,503 so we need to add that to the class. 146 146 00:06:26,503 --> 00:06:29,170 So, I can simply just hover over 147 147 00:06:30,049 --> 00:06:31,719 or actually I can just go ahead and type it in myself, 148 148 00:06:31,719 --> 00:06:33,181 I'll go ahead and do it the long way. 149 149 00:06:33,181 --> 00:06:35,089 So, I can go back to my TrackCoach class 150 150 00:06:35,089 --> 00:06:39,128 and I simply need to create a no argument constructor. 151 151 00:06:39,128 --> 00:06:40,961 So, public TrackCoach, 152 152 00:06:43,817 --> 00:06:46,309 open param and close param, 153 153 00:06:46,309 --> 00:06:47,650 and then there we go. 154 154 00:06:47,650 --> 00:06:48,932 So, this is kinda of a hack, 155 155 00:06:48,932 --> 00:06:50,349 not totally ideal 156 156 00:06:51,477 --> 00:06:53,625 but anyway, this will help us out 157 157 00:06:53,625 --> 00:06:55,371 when we get to the setter injection stuff. 158 158 00:06:55,371 --> 00:06:57,600 So anyway, I'll kind of leave it for now. 159 159 00:06:57,600 --> 00:06:59,761 There are minor issue here or there 160 160 00:06:59,761 --> 00:07:01,895 but we'll worry about that later. 161 161 00:07:01,895 --> 00:07:04,758 So anyway, that takes care of the actual compile issue 162 162 00:07:04,758 --> 00:07:06,444 and we're good to go. 163 163 00:07:06,444 --> 00:07:07,822 so, I think we're in good shape here. 164 164 00:07:07,822 --> 00:07:09,091 I mean, we covered on all 165 165 00:07:09,091 --> 00:07:12,505 of the basic constructor injection stuff 166 166 00:07:12,505 --> 00:07:15,099 with dependency injection. 167 167 00:07:15,099 --> 00:07:16,432 Good job, whoa. 13928

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