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: In this video,
we'll cover field injection
with Annotations and Autowiring.
Now, as I discussed earlier,
there are different Spring injection types,
and so there are the types that are recommended
by the spring.io development team.
That's constructor injection for required dependencies,
setter injection for optional dependencies.
Now, here's an injection type that's not recommended
by the spring.io development team
and that's field injection.
And field injection is no longer cool.
So in the early days,
field injection was very popular on Spring projects
but in recent years it has fallen out of favor.
And why is that?
Because in general, it makes the code harder to unit test.
Now, as a result, the spring.io team
does not recommend field injection,
however, you'll still see it being used on legacy projects,
and also you'll see it being used
in a lot of old blog posts on the internet,
and even in previous versions of this course,
I actually used field injection,
but now with modern times here,
removing the useless field injection,
and instead making use of construction or setter injection,
but I'll still show you a little quick example here
of using field injection just in case you encounter it
on some of your legacy projects.
Field injection is the idea of injecting in dependencies
by setting the values on your class directly,
even on private fields,
and this is accomplished by using Java Reflection.
So in step one, you simply configure
the dependency injection using the Autowired Annotation,
and so here's a code example on our DemoController.
Notice here we have this field private Coach, myCoach,
and we give the Autowired Annotation,
and behind the scenes,
Spring will inject a given Coach implementation,
and it'll do it behind the scenes even on a private field.
It'll automatically or directly set it on this controller,
and notice here, there's no need for constructors,
there's no need for setters,
Spring will set the field directly.
However, like I mentioned,
field injection is not recommended
by the spring.io development team
because it makes the code harder to unit test.
All right, so that's field injection.
So I wanted to show it to you
just in case you encounter it
on some of your legacy projects.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.