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
1 1
Alright, so let's go ahead 2
2
and dive in to Eclipse and we're gonna run 3
3
some demos here on Bean Scopes. 4
4
We'll take a look at those singleton scope 5
5
and a prototype scope and we'll see 6
6
all of this code running in action 7
7
and I don't know, just get a good feel for it. 8
8
The first thing we wanna do is, 9
9
copy our application context file. 10
10
We're actually going to create a new version of it, 11
11
so we'll take this existing application context, 12
12
we'll just do a right click and choose copy 13
13
and then, we'll simply paste it, 14
14
so we just do a right click and we choose paste 15
15
and this new version, we'll give it a new name here. 16
16
I'll call it, beanScope-applicationContext.xml 17
17
and so, with these spring config files, 18
18
you can really give them any name that you want. 19
19
Your project can actually have multiple config files 20
20
and here you simply reference the one that you want, 21
21
so you can call it anything, fubar.xml if you wanted to, 22
22
as long as you reference it with that name. 23
23
Anyway, I have my beanScope-applicationContext.xml, 24
24
now let's go ahead and bean it up, 25
25
let's go ahead and open this file 26
26
and what I wanna do is, I just clean it up. 27
27
There's some lines in here that I want to delete. 28
28
I'll select lines 10 and 11, I'll highlight those 29
29
and I'll delete these lines because we're 30
30
not going to use any of the property placeholder stuff here. 31
31
I'm moving down a little bit further 32
32
and I'll also remove that bean for myCricketCoach, 33
33
so I'll just highlight the lines 24 through 34 34
34
and I'll actually delete those lines 35
35
and I'll just clean up some of this white space, 36
36
move up and let's do a little quick check point, 37
37
so in this config file that we just created, 38
38
beanScope-applicationContext.xml, 39
39
these are the only two entries that we should have 40
40
inside of here for beans, so we'll have our FortuneService 41
41
and we'll have our Coach, that points to our TrackCoach 42
42
and that's all we should have, at this point. 43
43
Now, by default, since we didn't specify 44
44
a scope for our track coach, well, what's the scope? 45
45
Well, it's singleton right? 46
46
Basic information we've learned so far, 47
47
so it'll simply be a single bean, 48
48
now, everyone will reference when we run our application. 49
49
Let's go ahead and create another main app, 50
50
I'll call this guy, BeanScopeDemoApp.java, 51
51
so I'll just do a right click, I'll say, new class 52
52
and the actual name of the class again, BeanScopeDemoApp 53
53
and I'll also go down and I'll check the box there 54
54
for the public static void main, 55
55
because I'll have a main method, 56
56
just a little separate demo app that I'll use for 57
57
testing out this scoping stuff. 58
58
Alright, okay with all that stuff, hit, finish. 59
59
Alright, so we have a very simple bean scope demo app. 60
60
I'll just move in here and I'll just remove the 61
61
auto-generated stuff and I'll write some quick comments 62
62
here, as well as what I need to do. 63
63
This is kinda, you're getting really used to this now, 64
64
the first thing we need to do is, 65
65
load the spring configuration file 66
66
and then, simply retrieve beans from the spring container. 67
67
Alright, that's kinda the game plan, 68
68
let's write the code right here 69
69
and you should probably know most of this now, 70
70
from memory because you've seen this a lot 71
71
so this is good practice, this is how you can really learn 72
72
the technology, just by repeating it 73
73
over and over again, just like a sport, 74
74
practice, practice, practice. 75
75
Let me go ahead and use that ClassPathXmlApplicationContext, 76
76
I'll just do a copy paste, I say, new 77
77
and I give the actual name, so this is gonna be 78
78
the actual name of my new configuration file 79
79
that we just created, so that's 80
80
the file that we created called, 81
81
beanScope-applicationContext.xml, 82
82
let me go ahead and fix up the imports right here. 83
83
I'll just hover over and say, import that given class, 84
84
looks good and there we go, so yeah, 85
85
that's our new config file that we're reading in here, 86
86
beanScope-applicationContext.xml 87
87
so again, you can have as many config files 88
88
up here as you like for your project, 89
89
simply load the appropriate one. 90
90
Also, if you have multiple, you simply give 91
91
a common denominated list, you can load in 92
92
multiple configs if you wanted to. 93
93
Alright, let's keep it simple for now. 94
94
Now, let's go ahead and get some white space 95
95
and let's go ahead and retrieve the bean from the container. 96
96
I'm actually gonna retrieve two beans, 97
97
so I'll start off with the first one here. 98
98
I'll say, Coach theCoach = context.getBean, 99
99
I give the name, which is, myCoach 100
100
and then I give the interface, Coach.class. 101
101
Looks good, and also you can just copy paste this line, 102
102
for the second reference, so I'll 103
103
just do a paste on that one, instead of the coach, 104
104
I'll call it alphaCoach and everything 105
105
else here stays the same, so basically, 106
106
this is the code here for retrieving 107
107
the bean from the spring container. 108
108
Right now, it's a singleton, so 109
109
we should get the same reference 110
110
and we'll actually write some code in a second 111
111
to show us the reference, but I'll kinda pause for now. 112
112
In the next video, we'll write more code 113
113
to print out the results of this reference. 114
114
I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.