-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13. Spring Core Notes.txt
More file actions
1241 lines (687 loc) · 30 KB
/
13. Spring Core Notes.txt
File metadata and controls
1241 lines (687 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
===========
Framework
===========
=> Semi Developed software which provides common logics required for projects development
=> Frameworks will help the developers to implement more functionality in less time
=> When we use framework to develop the project, we can focus only on business logic.
==================
Types of Frameworks
==================
1) Frontend Frameworks : To develop user interface in the project.
Ex: Angular
2) Web Frameworks : To develop web layer in the project
Ex: Struts (Outdated)
3) ORM Frameworks : To develop persistence layer in the project.
Ex: Hibernate
=> By using Struts we can develop only Web Layer in the Project ( Controllers )
=> By using Hibernate we can develop only Data Access Layer (Persistence Layer)
Note: To overcome the problems of Struts framework, Spring Framework came into market.
=> Spring Framework is called as Application Development Framework
=> By using Spring framework we can develop end to end application
=> Spring is free & open source framework
=> Spring Framework developed in Modular Fashion
Note: Spring framework means collection of modules
==============
Spring Modules
==============
1) Spring Core
2) Spring Context
3) Spring JDBC
4) Spring ORM
5) Spring AOP
6) Spring Web MVC
7) Spring Security
8) Spring Social
9) Spring Batch
10) Spring Data JPA
11) Spring REST
12) Spring Cloud
Note: Spring is very flexible framework. It will not force to use all modules. Based on requirement we can pickup particular module and we can use it.
=> Spring is versatile framework ( Easily it can be integrated with other frameworks )
=> The current version of Spring framework is 6.0
=> Spring framework is under license of VM Ware Tanza...
URL : www.spring.io
===============================================================================================
1) Spring Core : It is base module in the spring framework.
=> Spring Core Module providing fundamental concepts of Spring Framework
1) IOC Container ( Inversion Of Control )
2) Dependency Injection
3) Bean Life cycle
4) Bean Scopes
5) Autowiring etc...
2) Spring Context : It will deal with configurations required for our Spring Applications.
3) Spring AOP : Aspect Oriented Programming
=> AOP is used to seperate business logics & Secondary logics in the project
Ex: Security, Logging, Tx, Auditing, Exception Handling...
Note: If we combine business logics & secondary logics then we will face maintence issues of our project.
4) Spring JDBC : Spring JDBC is used to simplify Database Communication logic
=> In java jdbc we need to write boiler plate code (repeated code) like below in several classes
=> Load driver
=> Get connection
=> Create Statement
=> Execute Query
=> Close connection
=> Using Spring JDBC we can directley execute query the remaining part Spring JDBC will take care
5) Spring Web MVC : It is used to develop both Web Applications & Distributed Applications
=> Web Applications ( C 2 B )
Ex: Gmail.com, facebook.com etc...
=> Distributed Applications ( B 2 B ) / Web Services or RESTFul Service
Ex:
IRCTC ---- MakeMyTrip
Passport --- AADHAR app
6) Spring ORM (Object Relational Mapping)
=> Spring Framework having integration with ORM frameworks
Ex: Spring ORM , Spring Data JPA etc....
Note: JDBC will represent data in text format where as Hibernate ORM will represent data in Objects format.
7) Spring Security
=> Security is very crucial for every application
=> Using Spring Security We can implement Authentication & Authorization
=> Spring Security with OAuth2.0
=> Spring Security with JWT (JSON Web Tokens)
8) Spring Batch : Batch means bulk operation
=> Reading data from Excel and store it into database table
=> Sending Monthly statements to customers in email
=> Sending Reminders to customers as Bulk SMS
9) Spring Cloud : It provides some common tools to quickly build distributed systems.
=> It provides service registry to register all our microservices at one place
=> It provides API Gateway to have single entry point for all our apis
=> Load Balancer
=> Monitoring
=> Circutit Breaker ( Fault Tolerant Systems / Resillence )
=> Distributed Messaging
=> Routing
10) Spring Test : It provides Unit Test framework
===============================================================================================
=============================================================================
Spring Core : It is all about Managing dependencies among the classes with loosely coupling
=============================================================================
=> In project we will develop several classes. All those classes we can categorize into 3 types
1) POJO
2) Java Bean
3) Component
================================
What is Pojo ( Plain Old Java Object )
===============================
=> Any Java class which can be compiled by using only JDK software is called as POJO class.
Ex-1 : Below class is valid POJO
class Demo1 {
int id;
String name;
}
Ex-2 : Below class is valid POJO
class Demo2 extends Thread {
int id;
String name;
}
Ex-3 : Below class is valid POJO
class Demo3 implements Runnable {
// run method
}
Ex-4 : Below class is not POJO because Servlet is part of JEE
class Demo4 implements Servlet {
// run method
}
===================
What is Java Bean ?
===================
=> Any java class which follows bean specification rules is called as Java Bean.
1) Class should implement serializable interface
2) Class should have private data members (variables)
3) Every private variable should have public setter & public getter method
4) Class should have zero-param constructor
Note : Bean classes are used to write business logic and to store and retrieve data
===================
What is Component ?
===================
=> The java classes which contains business logic is called as Component classes
Ex: Controllers, Services , Dao classes
=> Controller classes will have logic to deal with Request & Response
=> Service classes will have business logic of our project
Ex: Generate OTP, Send OTP, Send Email, Encrypt & Decrypt PWD etc...
=> DAO classes will contain the logic to communicate with Database
===============================================================================================
=> In a project we will develop multiple classes and those classes will be dependent on other classes.
Ex:
=> Controller class will call service class methods
=> Service class will call Dao class methods
=> In Java one class can talk to another class in 2 ways
1) Inheritence ( IS - A )
2) Composition ( HAS - A )
=====================
Car & Engine Example
=====================
class Engine {
void start ( ) {
// logic
}
}
class Car {
void drive( ) {
// star the engine
// drive the car
}
}
=> If we want to drive the car then we need to start the Engine that means Car class drive ( ) method should call Engine class start ( ) method.
Q) In how many ways Car class can call Engine class method ?
=> in 2 ways
1) Inheritence
2) Composition
============================= IS-A approach ========================
package in.ashokit;
public class Engine {
public int start ( ) {
// logic
return 1;
}
}
package in.ashokit;
public class Car extends Engine {
public void drive() {
// start the engine
int start = super.start();
if (start >= 1) {
System.out.println("Journey Started");
}
// start the journey
}
}
========================== HAS - A Relation ===============================
public class Car {
public void drive() {
Engine eng = new Engine ( );
int start = eng.start();
if (start >= 1) {
System.out.println("Journey Started");
}
// start the journey
}
}
Note: Tomorrow, if Engine class constructor modified then our Car class will be effected.
=================================================================================================
Note: If we use any approach from above then Car class will become tightley coupled with Engine class. That is not recommended.
##################### Always we need to develop our classes with Loosely Coupling ######################
=> Loosely coupling means without creating Object and without Inheriting properties we should be able to access one class method in another class.
=> If we make any changes in Engine class then Car class shouldn't be effected then we can say our classes are loosely coupled.
######################## To develop classes with loosely coupling we need to use Interfaces ############
package in.ashokit;
public class Car {
private IEngine eng;
public Car(IEngine eng) {
this.eng = eng;
}
public void drive() {
int start = eng.start();
if (start >= 1) {
System.out.println("Journey Started...");
} else {
System.out.println("Engine in trouble...");
}
}
}
---------------------------------------------------------------
package in.ashokit;
public class Main {
public static void main(String[] args) {
Car car = new Car (new PetrolEngine());
car.drive();
}
}
---------------------------------------------------------------------------
===========================
What is Dependency Injection ?
============================
=> The process of injecting one class object into another class is called as 'Dependency Injection'.
=> We can perform Dependency Injection in 3 ways
1) Setter Injection
2) Constructor Injection
3) Field Injection
-------------------------------- Example to Understand Dependency Injection --------------------------------
public class Car {
private IEngine eng ;
public void setEng(IEngine eng) {
this.eng = eng;
}
public void drive() {
int start = eng.start();
if (start >= 1) {
System.out.println("Journey Started...");
} else {
System.out.println("Engine in trouble...");
}
}
}
------------------------------------------------------------------------------
=> In the above program 'Car' class is dependent on 'Engine' object that means 'Engine' class object should be injected into 'Car' class.
Note: Car is dependent on Engine
==============================
Setter Injection (SI)
=============================
=> Setter Injection means, Injecting dependent object into target object using target class setter method.
public class Car {
private IEngine eng;
public void setEng(IEngine eng) {
this.eng = eng;
}
public void drive() {
int start = eng.start();
// logic
}
}
public class Main {
public static void main(String[] args) {
// creating target obj
Car car = new Car();
// injecting dependent obj into target thru setter method (Setter Injection - SI)
car.setEng(new PetrolEngine());
car.drive();
}
}
=========================
Constructor Injection ( CI )
========================
=> Constructor Injection means, Injecting dependent object into target object using target class constructor.
public class Car {
private IEngine eng;
public Car (IEngine eng) {
this.eng = eng;
}
public void drive() {
int start = eng.start();
// logic
}
}
public class Main {
public static void main(String[] args) {
// creating target obj ( Constructor Injection )
Car car = new Car(new DieselEngine());
car.drive();
}
}
==============================================================
Q) Can we perform both SI & CI for single variable ?
Yes, but Setter Injection will override Constructor Injection value.
public class Main {
public static void main(String[] args) {
// creating target obj ( Constructor Injection - CI )
Car car = new Car(new DieselEngine());
// Setter Injection - SI
car.setEng(new PetrolEngine());
car.drive();
}
}
===================
Field Injection - FI
===================
=> Field Injection means, injecting depending object into target class using target class variable is called as Field Injection.
public class Car {
private IEngine eng;
public void drive() {
int start = eng.start();
if (start >= 1) {
System.out.println("Journey Started...");
} else {
System.out.println("Engine in trouble...");
}
}
}
###### Note: We can access private variables outside of the class using Reflection API like below ######
public class Main {
public static void main(String[] args) throws Exception {
Class<?> clz = Class.forName("in.ashokit.Car");
Object object = clz.newInstance();
Car carObj = (Car) object;
Field engField = clz.getDeclaredField("eng");
engField.setAccessible(true);
// Injecting value to variable
engField.set(carObj, new PetrolEngine());
carObj.drive();
}
}
================
IOC Container
================
-> IoC stands for Inversion Of Control.
-> IoC is responsible for Dependency Injection in Spring Applications.
-> Dependency Injection means creating and injecting dependent bean objects into target bean classes.
Note: IoC container will manage life cycle of Spring Beans.
Note : We need to provide " Java classes + Bean Configuration " as input for IOC then IOC will perform DI and provides Spring Beans which are ready to use.
===================
What is Spring Bean ?
===================
-> Any Java class whose lifecycle (creation to destruction) is managed by IOC is called as Spring Bean.
-> We can represent Java class as Spring Bean in 2 ways
1) XML Approach
Ex: <bean id ="id1" class = "pkg.ClassName" />
2) Annotation Approach (Recommended)
Ex: @Component, @Service, @Repository etc....
Note: In Spring we can use both XML & Annotation approaches. SpringBoot will support only Annotations (no xmls)
=======================
How to Start IoC in Spring ?
=======================
1) BeanFactory (Outdated)
2) ApplicationContext (recommended)
Ex: ApplicationContext context = new ClassPathXmlApplicationContext(String configFile);
Note: Bean Configuration file contains Bean Definitions
(target class, dependent class, Dependency Injection type)
Note: When IoC container started it will read bean defintions from Bean Configuration File
and it will perform Dependency Injection.
===============================================
First Application Development using Spring Core Module
===============================================
Pre-Requesites : JDK 1.8v, STS IDE
1) Create Maven Project in IDE
2) Add 'Spring Context' Dependency in pom.xml file (search here : www.mvnrepository.com)
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.22.RELEASE</version>
</dependency>
</dependencies>
3) Create Required Java classes (Ex: IEngine, PetrolEngine, DieselEngine and Car )
4) Create Bean Configuration File and configure Bean Definitions
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="petrolEng" class="in.ashokit.beans.PetrolEngine" />
<bean id="car" class="in.ashokit.beans.Car">
<property name="eng" ref="petrolEng" />
</bean>
</beans>
Note: Here <property/> tag represents setter injection.
5) Create Main class and start IOC Container to test the application.
public class App {
public static void main(String[] args) {
// starting iOC container
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
// getting bean object from IOC
Car car = context.getBean(Car.class);
car.drive();
}
}
=================================================
Difference Between BeanFactory & ApplicationContext
=================================================
=> BeanFactory interface having - XmlBeanFactory as implementation class
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
=> ApplicationContext interface having - ClassPathXmlApplicationcontext as implementation class
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
=> BeanFactory will follow Lazy Loading concept that means when we request then only it will create Bean object.
=> ApplicationContext will follow Eager Loading for Singleton Beans. For Prototype beans it will also follow Lazy Loading
-----------------------------------------Note: Spring Bean default scope is Singleton----------------------------------------------
Eager Loading means creating objects for Spring Bean when IoC starts
Lazy Loading means creating objects for Spring Bean when we call getBean ( ) method.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Note: XmlBeanFactory is deprected that means it may not available in future versions of Spring.
Note: It is recommended to create IoC using Application Context.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Main {
public static void main(String[] args) {
System.out.println("===== BeanFactory Started =====");
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
System.out.println("===== ApplicationContex Started =====");
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
Car bean = context.getBean(Car.class);
bean.drive();
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
==================================================================
How to differentiate Setter Injection & Construction Injection in Bean Config File ?
==================================================================
=> <property /> tag represents setter injection
=> <constructor-arg /> tag represents constructor injection
<bean id="petrolEng" class="in.ashokit.beans.PetrolEngine" />
<bean id="dieselEng" class="in.ashokit.beans.DieselEngine" />
<bean id="car" class="in.ashokit.beans.Car">
<property name="eng" ref="dieselEng" />
<constructor-arg name="eng" ref="petrolEng" />
</bean>
Note: When we perform both SI & CI then SI will override CI value.
==============================================================
============
Bean Scopes
============
=> Scope represents how many objects should be created for a Spring Bean
=> In Spring framework we have below scopes
1) singleton ( default scope )
2) prototye
3) request
4) session
=> To represent bean scope we will use "scope" attribute
<bean id="id" class="pkg.classname" scope = "singleton | prototye | request | session " />
-> Singleton scope means only one object will be created for the class in IOC Container. This is default scope of spring bean.
-> Prototype scope means every time new object will be created.
Note: request & session scopes are related to Spring Web MVC Module.
===================================
Why Spring Bean is by default Singleton ?
===================================
=> To save memory of JVM spring team made singleton as default scope for the spring beans.
Ex: Rest Controllers, Controllers, Services and DAOs will be considered as Singleton in the project
Ex: TicketGenerator class is used to generate new Ticket for every customer
TicketGenerator ----> Singleton bean
Ticket -----> Prototye Bean
===========
Autowiring
===========
=> We can inject dependent bean into target in 2 ways
1) Manual Wiring
2) Autowiring
-> Manual wiring means programmer will inject dependent object into target object using
<property/> tag or <constructor-arg/> tag using 'ref' attribute.
<bean id="dieselEng" class="in.ashokit.beans.DieselEngine" />
<bean id="car" class="in.ashokit.beans.Car">
<property name="eng" ref="dieselEng" />
</bean>
-> Autowiring means IoC container will identify dependent bean and it will inject into target bean
(we no need to use any ref attribute in bean configuration file)
-> Autowiring will work based on below modes
1) byName
2) byType
3) constructor
4) no
Note: Autowiring will not work bydefault, We have to enable autowiring on target bean like below.
<bean id="id" class="pkg.Classname" auto-wire="byName | byType | constructor | no " />
==========
byName
==========
=> byName means IoC will identify dependent bean object based on bean id or bean name.
public class Car {
private IEngine eng;
public void setEng(IEngine eng) {
System.out.println("setEng ( ) method called....");
this.eng = eng;
}
public void drive() {
int status = eng.start();
if (status >= 1) {
System.out.println("Journey Started..");
} else {
System.out.println("Engine Trouble");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="eng1" class="in.ashokit.beans.PetrolEngine" />
<bean id="eng" class="in.ashokit.beans.DieselEngine" />
<bean id="car" class="in.ashokit.beans.Car" autowire="byName"/>
</beans>
Note: In the above example Car class variable name is matched with 'DieselENgine' bean id hence DieselEngine obj will be injected into Car.
========
byType
========
=> byType means IoC will identity dependent bean object based on data type of the variable in Target class.
private IEngine eng; ====> data type of eng is IEngine which is an interface
=> If one interface having 2 implementations then there is a chance of getting Ambiguity problem. To overcome that we need to use 'autowire-candiate' attribute.
autowire-candidate="false" ====> Not Eligible for Autowiring
autowire-candidate="true" ===> Eligible for Autowiring
Note: As an alternate for "autowire-candidate=true" we can use "primary=true" to consider bean for Autowiring.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="eng2" class="in.ashokit.beans.PetrolEngine" autowire-candidate="false"/>
<bean id="eng1" class="in.ashokit.beans.DieselEngine" autowire-candidate="true"/>
<bean id="car" class="in.ashokit.beans.Car" autowire="byType" />
</beans>
(or)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="eng2" class="in.ashokit.beans.PetrolEngine" primary="true" />
<bean id="eng1" class="in.ashokit.beans.DieselEngine" />
<bean id="car" class="in.ashokit.beans.Car" autowire="constructor" />
</beans>
===========
constructor
===========
=> It is used to perform Autowiring by calling target class constructor
package in.ashokit.beans;
public class Car {
private IEngine eng;
public Car(IEngine eng) {
this.eng = eng;
}
public void drive() {
int status = eng.start();
if (status >= 1) {
System.out.println("Journey Started..");
} else {
System.out.println("Engine Trouble");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="eng2" class="in.ashokit.beans.PetrolEngine" autowire-candidate="false"/>
<bean id="eng1" class="in.ashokit.beans.DieselEngine" autowire-candidate="true"/>
<bean id="car" class="in.ashokit.beans.Car" autowire="constructor" />
</beans>
===============================================================================
Note: Autowiring is applicable for Reference Type variable (not applicable for primitive types)
====================
Spring Bean Life Cycle
====================
=> Life cycle means starting to ending or birth to death
-> Thread Life Cycle
-> Servlet Life Cycle
-> JSP Life cycle
-> Spring Bean Life Cycle