All language subtitles for 022 Bean Scopes - Overview_en

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

Instructor: In this video will cover bean scopes.

Scope refers to the lifecycle of a bean.

Such as, how long does the bean live,

how many instances are created, and how is the bean shared?

Now the default scope in spring is singleton.

Okay, so the default scope is singleton. Very important.

What is a singleton?

Well, Spring Container creates only one instance

of the bean by default, and it's cached in memory

and all dependency injections for that bean

will reference the same bean.

All right, so it's just a singleton,

one single item that's created in memory

and shared amongst different other items.

Here's an example of this.

So I have this demo controller.

I have two references here, myCoach, anotherCoach.

I'll inject it using qualifier CricketCoach, theCoach,

another qualifier in CricketCoach, theAnotherCoach,

and they both point to the same instance,

because by default, spring beans are singleton beans.

There's only one instance that's created.

Now, we could also explicitly specify the bean scope.

So in our class cricket coach

we could make use of scope annotation,

and then we give configurable bean factory

dot scope singleton.

There's additional spring bean scopes.

We already saw the first one here for the singleton scope.

There's also prototype scope.

It'll create a new bean incense

for each container request or for each injection point.

There's request scope.

That's scoped to an HTTP web request only used for web apps.

There's also a session scope that's scoped

to an HTTP web session.

Again, only used for web apps.

And then there's a global session that's scoped

to the global HTTP web session in the case of web apps.

Now let's take a look at a prototype scope example.

Now with prototype scope, a new object instance is created

for each injection.

So we have to specify the scope

on the actual class here the bean.

So cricket coach, we have scope

configurable bean factory dot scope prototype,

create a new one for each instance.

Let's look at a prototype scope example,

a new object instance for each injection.

We have our demo controller, we have our two fields here

and then we reference our cricket coach, the coach,

cricket coach, the another coach.

Since this is a prototype scope bean,

you'll get a new object instance for each injection.

So they point to two different areas of memory

or two different beans.

How could we check on the scope?

Well, we could write some code here

as far as a get mapping for slash check

And a return to results here.

So I'll say comparing beans

to my coach equals another coach

and then I put the actual expression here.

So this will check to see if this is the same bean.

This will return true or false depending

on the bean scope.

For singleton scope, they return true,

because remember

singleton is shared and it points to the same bean.

If it's prototype scope, it'll return false

because with prototype you get a new instance

for each one of them and they won't point to the same item.

All right, so this is really good.

Let's go ahead and dive into our IDE

and let's write the code for this and check out scopes.

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