New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Spring natraj-satya-best
1. SPRING
SATYAJOHNNY PRESENTS YOU
Download more materials
------------ VISIT---------------------
http://ameerpetmaterials.blogspot.in/
http://ameerpetmatbooks.blogspot.in/
http://satyajohnny.blogspot.in/
67. b{
Hx<-- -t-
trF
3
,-----..--{
q
Fo
a
;F
g
d
c./
l.
ig=l lE Fl E-lAEl le *l 5
L, .! tF Xt
l.l rO I /11
I F -ai lA ^Fl rb
l?fl ree-61 s--'Izsl EdE Rvd9
a^. F
C c-c
J
r-;----1 lETl
I glt lF ?1
I E gl ih$I C Jl I tr dl
l?B lsEjI r-'l .(
'---+ ;
j
d '.--,
ts
l]
{
F.
I
o -./
g
<.vA
Fj
5
r
i..-.
/--"r 9l- f F-d I I
lr xl 4'u : l}+l I I
leq {1g' l}-B.i I I
l-. Fl t l^ F 16 El L_l
I ?l 9-' h' ,{3I t^l F .tr-
a
a
68. 3l2DO13 9:21 AM
'l
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
'18
19
20
2'l
22
-23
24
z5
26
27
28
29
30
3'1
32
34
35
36
39
40
41
42
43
44
46
47
48
49
50
51
54
56
58
59
60
ol
62
bJ
64
65
66
67
68
Spring App on Interface lnjection and Bean posl proccessor lmpl
_Demo.java_*___
public interface Demo {
public String sayHelloo;
]
------.-------DemoBean.java--.----
import org.springframework.beans.BeansException;
import org.springframework.beans,factory.BeanFactory;
import org.springframework.beans.faclory.BeanFactoryAware.
impon org.springframework.beans.factory.BeanNameAware;
import org.springframework.contextApplicationContext;
import org.spdngframework.context.ApplicationContextAware;
public class DemoBean implements Demo,BeanNameAware.BeanFactoryAware,ApplicatjonContextAware
t //sp."iat Bean properties
-
tn*rat,* fu ffi-"', e";'l'ffi
private String bname;
private BeanFactory factory;
private ApplicationContext ctx;
String msg;
//setxI(c) for setter lnjection
public void setMsg(String msg) {
Systern.out.println(!!D€FroBean:setMsg(-)"):
this.msg = 659
)
//method of ApplicationContextAware(t)
public void setAlirjlioefctriqdffFtr(Apptieationconten dx)
throws BeansException {
System.out.println("DemoBean:setApplicationContext(_),,):
this.ctx=ctx;
]
//method of BeanFactoryAware(l)
public void setBeanFactory(BeanFactory factory) lhrows BeansException {
System.out. println("DemoBean:setBeanFrctoryC),') :
this.factory=faclory;
]
//method of BeanNameAware(l)
pub[c void setBeanName(String name) [
System.out.println{"Demodean,setgeanName(-),)
this.bname=name;
)
public String sayHetlo0 {
System.out.println("current bean id,,+bname);
System.out.println("current bean is singleton?,'+ctx.issingleton(bname));
System.out.println("current beab is prototype?"+ctx.isproiotypeibnamei);
System.out.println("all beans are',);
String idn=st(.gglgeanDefi nitionNames0;
for(int i=0;i<id.length;++i)
{
System.out.println(idfrl+"....1.
)
relurn "Good morning:msg="+rn59;
)/method
i//class
*----DemoCfg.xml----------------. --------------"
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.sorinoframework.org/schema/beans',
xmlns:xsi="http:/ wvw.w3.oro/200 ,,
xmlns:p="http://www. sprinqframework.oro/schema/p,'
roerlodS SrlPc'rnoi
nd +4Le lic*t oo
Page 1 of 2
69. 69
70
71
72
73
74
75
76
77
78
79
80
81
82
84
85
86
a7
88
89
90
91
94
96
o-7
98
99
100
101
102
103
104
105
106
107
108
109
1 '10
111
112
113
114
116
117
118
'r 40
31212013 9:27 AM
xsi:schemaLocation="httg://www.sDrinqframework.orq/schema/beans hfto;//www.sorinoframework.oro/schema/beans/sorino-bear
'Ee!jq:ll4 {q$='My?r999!!g{/> ,'.J Beo Post ?roccssrrr ConPiS t'raH cm
<bean id="db" class="DemoBean" >
' <property name="msg" value="hello"/>
</bean>
<bean id="df' class='lava.util.Date"/>
</beans>
----DemoClient.java------------------------------
import org.springframework.context-suppoIt.FileSystemxmlApplicationcontextj
public class Democlient {
public slalic void main(String0 args) {
//Activate Spring conlainer
FileSystemXmlApplicationContext ctx=new FileSystemXmlApplicationContext('.srcDemoCfg.xml");
// get Spring Bean class obj
Demo bob.i=(Demo)ctx.getBean('db")i
// call B.method
System.out.println(bobj,sayHello0)'
)/method
)/class
r Prwess<r{
import java.utll.Date;
import org.springframework.beans.BeansException;
import org. springframework.beans.faetory.config. BeanPoslProcessor;
public class MyProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeleitialization(Object bean, String bname) throws BeansException {
System.out.printlnC'MyProcessor; postProcessBeforelnitialization0")l
if(bean instanceof DemoBean )
t
DemoBean objl =(DemoBean)bean;
objl.msg="hello1"'
return objl;
)
if(bean instanceof java.util-Date)
t
Date obj2=(Date)bean;
obj2.setYear(130);
return obj2;
)
return bean:
)
public Object postProcessAfterlnitialization(Object bean, String bname) throws BeansException {
System.out.println("MyProcessor: postProcessAft erlnitialization0");
return bean;
]
)
Page 2 of 2
70. a- Fcrcrorg Becm : -
-> fP Norrrar 6ec(n i6
.Notmar 96..r-, class
ConP;6ured as De?eodepfBean fo
ohjed uirl be initucd d;rec*lg
Beon pop
h ka,o P1.?)Pcdtg
rescrr}crli ohieci otLro46' aP FactvgBeat
c|oss obect @il) Dor A(
Facr<q8ectt' r.r:itt bt
i5 si.rglercn ot rnf
Qocxrrces oF rbe aPPt'cafirm
r) fap6p,,lavc (sPingrntoFr'<
gftrnde.o,iava (sF""Sm
sJ ftmoCPg'rmt (sf,n'rd fitj
+; e*oBS' jara (cticnr Arr,.
G) TSi q€an'J&va (h.m'5Bc"n)
oalor/rora
e'rCTen
"---- l".rtog tsec.n s
a3
a bcan lbo-t 6enerarcs
ftpn&ntBeon tkn FectogBaaois con86u'rd
iai€Lted ro prufrr61g lx't lhe rgutkniBecrr) gc^'r'6c/.f€d bg
idet-rtd.
Eg:-
/*qfi id ="4b" class ='Testgeor''
/ z
Til5 inl(t%ce C6ofr'io5
Ne+Beao 5
tgw: [DEs)ur Pc'r &vc'
vendor'. 6uo11 5 (orc'cle aNP )
Ve{Sico: 6.1" I
66ren 50trr Ce
U'*U GtassFsb ex a5 beilts-io5el^al
to claorla'd slro : wNN'nerkan6'6{3
Po ducs, nnr^r' rrrbeans 'cng
0 g"rOhir.tc I
@ ouObtJTvt'L')
-----
@ isSi"gtto" L)
-t
L**cto id;''db' cla35 : PcnoBerto"Pz
zFrB^tts rp'me ="t1" r€P--'rb"i
7 ' I
zl&t'n>
"61" pro*'ag o? kmoBeon clrrss
iP "Iest8eap" nrrrd fi^mng!ec'n
+htn lbe El lrrutu"d
(oirl be lqjetrtd u'ifi 'TestB€on" cusS Ohj'
ip "Testgean" b s Facfo!$ Bron rben the "L'' P^ru"s oP
"*'::."
61619 toilt b€
lnr4Hi coirh rhe wsulhnJ obe{r $t''tn
b: TestBean
coss
o - - ( rl
SprrngBao brroroes F.oorg Bcar, ohn ib trnplerrrnr' O-'S''F ' bean6'fc'ct<l't
'
.latrr"iLia'n
' '
3 rrrrbods
r€rurns *. ,*'*1"1,trr".- *t
rerulr),5 rhe tgPa 4 rs
reJLc6n'9
tl earbe-r YLsa lKrLf o hiet*
75. /10e.qoCPd-.*t
2b4o.9s>
/Uf,o$ id = fb Clcr!S-- Jefl,sc6rt /
.;;lt .til
*:,L*-="
l"lto' Iz
Si&i + rab$0e({
arrtrshfet i
i // l- Potaro C$nfiuj.rrl/
EemoBeao ( Ta,B*", rb)
{ 65.o=o:
S o. P [ ''
frnogs6e" 4- PararD
o
J
//rnerUocl &4 &Jfu e'q crl'lcr'-,
firbti c Void SerTb (Tes$er.n tb)
{
€ o P("cxmo$rrr' : sfTb[-) wtfiod "
),
lhlr. tb= Eb ,
{rrblrc SU"g *.gHa-ro 61
t
irgran tgtodan*r,]tt3 Tqhf&on'nzs $ = "+Bb;;
5
// IeltBtr.n ic.rra
ccsnsrnrohol ' ))
-
-/
Publlc
t
ccrss Test8ec.n
/&"o f"fg'nr
3i'rn5 r'ts3;
/ltrts .rsrroa &r se-tttnJ+jcrfirn
pubic y6i4 ,.rfitg [5r'r"g m$)
{
llrts ' msg -- n t3 i
]
/ imptemtn-r to $'lngL) rrr,rhoc
lnL{ic Sung tSh;n61;
a
t
Yefaln *t8i
L
l'
76. a- zlbeqo >
L*c$ id = "db" class = Denro Beao"
zlbec.o s >
//ftmo Cricnr -.pva.
pLtbic clo56 DerooCuen* [
p s v rn fSr*ngrl fttss)
a
L
l/ruivo-te SPYlnS Gmia;rr,t
ChssParbXrntftpticcrrr on C:n ru t
llner sg-rtg &r.n rihi
d-qfotoire =' 9 N<.m6" 1 7
-I ft" ttu a
'fra
D.,ooBe<rn class B€&o prDp<^!
ood TestBran c krss Bec..,; cl ( bb) rrrr ,-*.hC+
b)
or-l = rle&r 61og5paJb
rmr ftpp)rz''hl <rn Conlex- C'Y"fr
k
the kc'oid
Oaro o:ire =
Demo 5eq1 = (gemo) crx ,gelBean ('au' );
)t Col- a. rnettncl
S o. P (uou; . ssJHeuoL ) )j
I
;cr sPdogCcnr8gurc*krn Bre roel be
"4TuPe Codeing ssnngcPg krc".-
//in ktrncfu.xrnt
Zl0ocrype - -. -. z
/.beoe5>
zbecn id-'tr " c1c65 -"-lestBEoo' 2
zfrotl,.tg ,'11ens:"msS votueJha'l-o' I 2
lll.dln=
z-btsrt id =-db" clcas :' DerroBean " aitrbo@irr =''4'TUPe" / z
-
L[r'e rhe &a@oo-,a Lb'fune TastBeaD
zllaos2 ana rfre nn"UegrUh* "br" tgpe(rcstc<oo'
9n rnatiipc.fimes toirb Efa*"1-
Utt$re ict. otho<':lse q"{qt*),gy
nrJjJ Ic,i4 cumbi5urry
t.H9"
Noc""-
lilrn you CarrB5urc SomeTestBean cicrss
lSeooid's *reo fuTgOe mode c'P autur:rirtng
D
4xf6&rite : Gmshru(tl COdeing Sp,yingcFg fite;-
.{ l0ocrgpe
rnat YCriSe CrmbiSt-,.ti Ptod€ms
77. Zbcrra >
/hn-r,n id -' tr"
4Pr1J|,eftg
Ll?af)>
zlVons>
Oulo(I)il€ = or(fodeftCt
61q.q5 =" Te$B€c.n" )
rr!mez''rns8r1 Vakre-" t
"tNh
*t^.-*?:l*{ $'ov -r'n'4r.
,_-/
vt I
I/
I
c.lcrrs n& st l-r.rr .l--p<rmty;'
z&n id='hb" clors= EmoBa"'" crrl&ocoire = Consrru o-rcrf
--iR"for 61,d"SB-"
codo'ng 6frhg Ccm$SLtrafio'r -3re :-
lWo6'2
zb€on 'ld 1'tt' et&16 =''TestBeaD" >
Zl^D[s% rrirn€ --n55" 1t''tote:*bellb" /z
4beao>
Ltreun id=tb' c1435,=- DemoBean
zlVcoos>
fonevrratq lar-r ing Tat8rcn lns rt, e pdrc,rDfu,0e. J
Cfhc",<-olre S1-.6Got<,fnr'r y"tunS
:
arr-lotoire J ut*te"+ "
I z
-_-_-@-
C4mStrufL^/ th.ln SfrA nS Cclnt-cnrr,'t
grrfirtmO
- Qotnllrntilrn J4rurq
g Nho. l-{T'rx6 iPcoe coohgured lsrb c.drlurtn"S 4 sxpLiclrc41i'''n9 *
?ffi
ry * borh orJccoldn5 (taqlrct uridnS gtPtnta Sertcri{eooo rltq
ouiocniril in One Sp'lngB'eoD ctn'sS '
Onggrre C*ftoi. l$ofrnrf.g Pzn enpbcr't Urtnng crnd Centcrln Otbr'v prrqv'n]<g"',
b-,,iria3 1ai ll ePk l t +pu"a ) .
Curfooldng {e'gf'rc-l+
tolnnS ptfc,-tns Consracafc* i4.,n* tlO
1? 6*t CLrtooif.og g'rPorcns )r$Uaorr CLocl erptrcit coftlg fletfrnrs -
the o.grit mng t^ir eeftc4'
Coqsh-rlclor iticrHon fuZ ot tlise
S?rkl:s'{e*roo 14)rr bL e€&,kd "
fh.r the c,ll*n; fh"t fr"&t^n
$o'b 66nrcrrne6 (B€onfaqtduco*ccrru' { +oou** cc'ru-e}i csn{-cat.''^
) t,{rtos
gerko(
Vorsa
@ xf &.mo[&on c[r-snot conkan arrl ex{xicit
^
$!rrJ to.fe setu4%<rr16n
hle ccrn
f.
tre expict
aP both
Cu-tfooirYlU-
78. L0bite usiDg Spriog cortt, 6rbe'r Java tf.hnologies ib i5 fecorD€nded hr placa $e
logic o€ attiva-Fing SfJ'iog C{tor.dn€/l &nd g€tttn3 Sftnng Beato clcrls oQierr in
one F me exer'l-Lbl crn bloc.k ccri,l e d ccfn SYtucf&i tcrt) 6t Lri c b [ocr<
- + fi'n"U u,gbgL Ib i5 reroocnded to cc'rt EusiDess rnebocl C&6) SPnDg Eeao
Clio("d App
Awi/ tuing frame
Apprer / ctgp+
&rvter Prq
.)5P Pr3
6h{hs App
JsFAPP
P)ace ro o$ivale sPnng Crsoirrine4
ctnd ro getsP,loggean des6 ohj
&rostrc'cfol / S*rf . Ut.r+
ftrrsrrulcr / slzir..,. blook l initC)
CorDSr&aJz" I Storic b0+ f inirc )
z-t I PU.t]i c roid ispfnitt )
{_ _-
- ---'1 "/.>
cost&cfrd /Soui. blocta 64
gl-rat5, Acficm class
Gmthulru{
l*. btoc.!-dF
Homged Ber*n
Pace 16 corr b'roertrods
of sp*ng8enn
Eveo bandt'n g rn crbocts
&rqe
serv;ce(-,*) /
aoX^x e'J
L'/"
-"--"/.y
€xealre(-r-r*' -) "P
Errc*s Auron dass
b.rrrrfiod oP
llaocged Sear1
79. fP Java oleb o?pl)cction u6es opringAPI (rtr"d garg APJ) in tbe toeb rcsoerce pyoflrcrms
tben trne Sp6r€ Apr relarcd rrD; n iaY gle sboatd be cdde d l-o CLAIII;aI H oDd
6pnn{Ap1 retrfid rc4tn and dePeDdent iot Ftes sFnrrd !e crc{ded irr r,]EB-J^1F/ltb lot*',,,
jar eie e ddded fD C LAsnpAr H to)rl be used bg iovcr ComPt)e"r dtrr;og the (orfD'] idfi atl 0'f" .J
tncby€ Socc(.e pyDgramo L6en,ner ft35 ) to 'f.cq,n;ze Sf dng c.Pi. qjar Filee qdded )
NEB-INF f iU ftraer Loirr be used Se{vteJ Contdod /j5p confrd r€.( ho re<og nize ond v;
c6eg gpring api ')
Reglt 6<t ohieci i6 Dor a Serlaizable ohJect ' so' @e cod E seocl Qesurtgef ohleu
-7
ove( $e netaorv ' To solve 15''t problero lbe{e ore troo Goluhons -J
sola$onO :- ugs Roco6€-rs insrcod o? Be$t-trt$et
--2
--'' I?oarsers are Se'rl&li7&be ohiecrs ood u:e cGo 6e|-rl lhero over ftp nftocrt h - r
-/'
Rocoters
-
->
All collec$(In fiornec'rc;r I"
orare*s . 50 Loe cctn €end rbero ove'r the r8-r{rrcnk '
,"__;, ;r;;.; ";-;;,,*
ou.r ru co,re,j'srrrlqroelrdk
Dcdas.{udq}e '-
r'r-t ?ft "' IdYf 6eft id't/zq,-ble-
0*a$rtuc-rures
(lire ArroiLl6t ord e-rc"' )o'e
Senia-t'rz<'l:teu
S0ltrdon@ it good
.'-^^ '{-,p. trkl coorc'n3 -
-> rP gan &re lbop,,nS 16 lrtPolm onl9 Read o1x'r'Ho"t
i^rn 1:
coirh Non- &nr,von'rzed
o*tt'-*.,*' R'r B**tPt*H;"i1^f I :
-,
Jp rou crye mgnq rd ?e'r*,,m borh Read
"tt.-:"#i::H"*"*:
ptn Smft:rr
rt tt{r{V-,o$ toth fuocbroruzed
96'655c'c'kc-rf
ror
--,,
(g3:- vecrt", tosbT&be ond erc " ' ; -/
-) frleo$ougb OeK,"(F- is rgt fiee ib is rtrt recornerded lo Scnd Pesurr5et o hie4' ftot.
&rrinorioolcr6cr to 6arrcelrrlcr d;rettg ' Xt it vt{zr.icnled rD keep rhe Ytr$(ds oe
:
pfsci,t*r;t In Col le*rcrrrFrarneux,rk hrr^err..cru< onl eenA rhaf Dc.tt 56-a t*r.t"e to _,
kem"Hct ).or1t^l .
80. urtdeteranding probtero ro coPg #)e records o? l2e sar r3+ o$ of ,{rraXlls t 0rra Srn^ct<r6
gFR r s (Res&{rgrr obj ) cl(
YAJ q IrSa -
V7-
<jb I ', Qfnq u,^Jl
ALa
E-ocb eemeoi
Reart t&t csntui n 5
e6ch, rtCcrd Of
Arra6l-i sr obj )
oP ArrcrdLi 6i Gllosro opl$ one ohje* or o h me ' Eacr' vecord oP
mutliPle vques incluct ing rrxJliible 6$e{5 ' so) toe carl c coPj
Qesrtr 3<-r to eoch) eleroeDt dF Arrog List dtreull .
----> To &lv€ 1hr aboYe
obreLh on& add IfBr
here, thts urel degned &vq cld56 ii genefoJrg q Jhvc{oec,n allli'ng
dn d ]b t5 crued cs v,o ' closs / D't' O ttt'*t
probero KeeP ec'cb f,ecurc{ vctlLr€s in USer Deened Jav aclcLs
ohjeif tD eocb elerncot oG orro4Li6i cts $roon bolur't
Cvoue Objeo ctess) (D*atrc'ns f<,r OhPtr
Qesul t 6cf obj rtcoxd e fo ,l"c'6 L;s f
clcrs s )
e leroeD tS Usiog V'o'tcrss/O"r;Po,
i4tc o -lroosFcl
Sr,tlenlBeao (o r'o ctossJv'o ctoss)
pabric ctos6 Srr,&nlBeon :prt=$-e"elA'gSE$e
f
L>maodi r(Icq
/bt6o ftruftt{-ies
int SDo;
SMng sr,&rne ;
Sfrir,g 6cdd ;
// t"ltite ser*s { gen'cnr
...
I
!9!E:- ohieLrs erdded to '*re elemenrS oF Coleu{6nFrarr€c:s6k
Drftt6n&cr''Ye
trrY€n c.5 Senncriznjcle Ohlerrs inatder to &nd Gratricrrframerl:O&
D:rro5wuGuYe Ovfi ltre nerrl:o.tk '
61q6t be