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
-: All right, so now we'll move in here
and we'll make use of our alternate solution.
So the first step here is the Create a Configuration class.
And what I'll do is I'll first-off put this
in a separate package,
so I'll create this new package called Config.
So in the spring core demo, I'll have this new package
and it's, dot config.
All right, so I have this config package,
now let's go ahead
and create this new class called SportConfig.
Okay, so we have our Sport Config.
Now it could be in any package, it could be any class name
but I just like to use the word config because,
well, it kinda makes sense, it's a config.
I'll make use of this annotation here, Configuration,
and be sure to choose the annotation Configuration,
not Configurable, okay?
Configuration, as you see here on the screen.
And then we'll cover Step 2 of Defining a Bean method
to configure the bean.
I'll make use of this Bean annotation
and I'll create this method, public Coach, swimCoach.
It's gonna return an instance of a SwimCoach,
so, new SwimCoach.
And we're manually handling the construction here
for this given coach.
And then remember, the bean id defaults to the method name,
so the bean id in this example is swimCoach,
with a lowercase s.
And we can use that
when we inject it into our controller.
Alrighty, so kind of zooming out here for a bit,
and we're okay now, we can go ahead
and run this application.
And then, success!
Notice here, our diagnostics printed out,
In constructor for SwimCoach,
so hey, it's actually creating in a swim coach
and making it available
and the application started up successfully
so nothing failed.
So this is also good.
So that SwimCoach was injected into our Controller.
And then we can verify this by swinging
over to our web browser and then going
to localhost:8080/daily workout,
and "Swim 1000 meters as a warm up".
So that comes from our actual swim coach,
based on its configuration.
So, remember SwimCoach did not have the Component annotation
and it failed the first time we ran it.
And then we simply configured this as a Spring bean
using the Bean annotation,
and then everything worked out for us.
All right, so this is more of a contrived example,
but from that real world example I gave you a little earlier
the whole idea of making use of the Bean annotation is
to take an existing third-party class
and then wrap it and expose it as a bean
that we can use in our Spring applications.
All right, so I'm not done.
Let's play around with one more thing here.
Let's swing back into our code
and now let's give our bean a custom id,
so instead of using whatever the method name is,
let's give it a custom Bean id, and we can do that
by simply providing a string here for this bean annotation
and I'll call this bean, aquatic.
Just making something up here.
So that's the bean id that we can use.
We can swing back over into our controller
and then we can inject that given bean id.
So we make use of our custom bean id of, aquatic.
All righty, everything should kind of reload there for us.
And now if I swing back over to my browser
and do a reload, then everything still works as desired.
So we're still injecting that swim coach
and we can still make use of them.
So, this is great. I'm happy.
I like it.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.