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
Instructor: All righty, let's get started.
So we'll do our normal housekeeping work.
And let's move in here to our file system
and we'll copy this directory, 07-bean-scopes,
and we'll paste it and we'll give it a new name.
And the new name we'll give it is 08-bean-lifecycle-methods.
And let's go ahead and open this project in IntelliJ.
And one thing I'd like to do here is just some cleanup work.
I'd like to change the code to inject only one coach
and to use singleton scope.
Just want to kind of keep it simple.
Give me some good baseline code to work with.
I'll move into the DemoController,
expand my window here for a second,
and I'll remove one of the coaches here.
So I'll remove this anotherCoach field.
And then I'll also move down here
and remove the qualifier for theAnotherCoach.
And fix the curly brace here.
Remove this line with the assignment.
And so this is kind of what my constructor should look like
for the DemoController.
And then this GetMapping for check,
we'll go ahead and delete this section of code also.
All right, so this is basically what our application
should look like or our coach should look like
at this point.
And then I'd also like to go over
and make the change here to CricketCoach.
And so I want to remove the prototype scope.
So I'll just delete this Scope annotation here.
All righty. So this looks pretty good.
And then we can kind of get down to business here.
So step one of defining the methods for init and destroy,
and then adding the annotations here
for @PostConstruct and @PreDestroy.
I'll just write some quick comments here to myself
just to kind of keep myself on track.
Okay, this is our basic game plan here
defining our init method
and also defining our destroy method.
So I'll start here with the init method
and I'll make use of the annotation PostConstruct.
I give a method here, doMyStartupStuff.
Again, you can use any method name here that you want.
And then I'll just do a little print line statement here
just to let them know that hey,
we're in doStartupStuff for a given class.
Alrighty, this looks pretty good for our PostConstruct.
So this is our init method.
Let's kind of copy-paste this
and let's do a similar thing here for PreDestroy.
So I'll just paste it.
I'll update the annotation PreDestroy.
And then I'll just move down here
and just give it a new method name, doMyCleanupStuff.
Let's update our print line accordingly.
And that's the coding there for our destroy method.
It looks good. I like it.
Now let's go ahead and test this out.
Let's just run our application.
Our app is up and running.
And one thing to notice here,
we see the code or the execution of our init method here.
So in doMyStartupStuff for CricketCoach.
So notice the previous line,
we're in the constructor for CricketCoach
and then we have our custom init method that runs
as a PostConstruct.
So this is great. I like it.
Now if I stop the application,
then we should execute our PreDestroy method.
So we're gonna just stop, scroll down a bit,
and then we'll see that this print line here
in doMyCleanupStuff.
So this code is actually executing as desired.
So this was great. I like it.
Good job.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.