Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
25 views
Spring
Spring module
Uploaded by
varun varun
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Spring (1) For Later
Download
Save
Save Spring (1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
25 views
Spring
Spring module
Uploaded by
varun varun
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Spring (1) For Later
Carousel Previous
Carousel Next
Download
Save
Save Spring (1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 21
Search
Fullscreen
What is loc ? IOC: Inversion of Control > 10C isa principle which is used to manage and collaborate dependencies among the objects in the application. Managing ( Creating the object) , collaborate (Injecting the object) > In Spring, OC is responsible for Dependency Injection. UserDe ‘Servic Repro freporsersie oa ‘AdminService K——|Adminserviet} UserDae object injected into UserService, UserService objet injected into UserServlet(am _/ annotations) Programmer are responsible to Configuration e ‘write configuration g Inspring boot-auto conguration aa - Classes roc [> soring seans Note: Fr IOC we need to pas ava Classes + Configuration as input then IOC wil produce Spring Beans. Soring Bean: The class which is managed by IOs called as Spring Bean How start IOC container? => We can start in 2 ways 1) BeanFactory (1) (outdated) 2) ApplicationContext (|) (recommended) (Interface) (class ClassPathXmlApplicationContext) ApplicationContext ctxt = new ClassPathxmlApplicationContext( String xmiFile)fo Benaensecce————————————n 2 totaal CPoarimnensim ant — PERGRETRER Semunse meep://moven.opocne.org/run/s.0.8 2 Gmoselvereson>4.0.8¢/modelversions 3 thik /groupTad> 4 OC-APP«/ ar2sfactid> 5 SMAPSHOT< vers on> 6 8» dependencies? 18>
Bi
12 Greitactidvepringreontert/artifactig> 23 Gersion$.3:25c/version> i esoentonePaymentService doPayment(..) Tayment.paynent; LI Debit credit] Sodex] [Amex ‘App Test public class Paymentservice { private 1Payment payment public PaymentService() q System.out.printtn(“PaymentService Constrictor Executed"); y public PaymentService(IPayment payment) 4 System.out.printtn("1 parameter PaymentService Constructor Executed"); this.paymentspayment } public void setpaynent(rPayment payment) 4 System.out.printin("Setter method called”); this.payment=payent } public void doPayment (Double billtnt) jayment..processPayment(billémt); if(status) ¢ System.out.println(“Recipt printing....") + else « System.out. println("Card Dectined. y } }public interface TPayment { public boolean processPayment (Double pubite class DebttCardPayment snplenents billamt); ‘TPayment{ a public DebitCardPayment() it Systen.out.printtn(“DebttCardPayment te ae eee ees Syston out. prentn(‘evtcardrom Irayment ( } public boolean processPayment (Double pubtic CreditcardPayment() bintawe) ¢ . System.out.printLn(“Debitcard Payment Systen.out.printtn(“Credttcardbaynent Saab Constructor Executed"); return trues y public boolean processPaynent(Double billémt) ¢ | System.out.println(” Credict ¢ Payment 3 Sucessfull...")3 return trues } } public class Test { public static void main(String[] args) { J/ Start IOC container using ApplicationContext ApplicationContext context=new ClassPathXmlApplicationContext("Beans. xml") // How to get the object from the TOC PaymentService service=context.getBean(PaymentService.class); service.doPayment (200.00); i -B>W OOD W0e+O-O-a Awe S 4b hiewer ora sremrtyow i Gtontigee = 8 Bieocamiemet Giperetne Dteeete sts aa ea Google stpteencenoutenan! fe x(n eee ss) (sptghat) aoe) (pe) (om) (Sa) (sap) (Hee) (Sn Sotasoe © iene en mtcndeesin f 40. XML Senema-bated confguation‘Te cquale Hem eA Sehons sto wause thaaptaer Gramime =D) ReECeynn Boman armen entacarets Atyenine ta “| echeans anlnae"http://hom.springfranever.org/schena/beans* 3 etapa ney nna ymeascene nee 5 fier eae ser caeraheenWiees/atuasirtane WiGaT TAG aptagrrescseH 5 ce bean definitions hare ==> BS cibeane>
setter injection
Note: ref att ute represents which object should be “
—>
public class car { private TEngine eng; public Car() { System.out.printin(" Car constructor"); public car(ZEngine ene ( Systen. out. printin("Ca Constructor"); ‘this.eng = engs + param - public void drive() { int status = eng.start()s if (status >= 1) { System.out.printIn( "Journey Starte } else { System.out printIn("Engine Trouble... y } ?public interface Engine { public int start(); y public class DieselEngine implements TEngine{ public Dieselengine() { System.out. println( ‘DteseLEngine. Constructor. y public int start() { System.out.println("DieseLEngine starte return 35 } Y public class Petrolengine implements Iengine { public PetrolEngine() { System.out. printin( ‘PetroLEngine. Constructor. y public int start() ¢ System.out.println("PetrotEngine Started... ")s return 15 y y| public class Test { public static void main(String[] args) { ApplicationContext ctxt_= new ClassPathxmlApplicationContext("Beans. xm") Car cl = ctxt.getBean(Car.class); cl.drive(); + ea ( cbeans xmlns="http://uww. springframework.org/schema/beans" | xmlns:xsi="http://umw.w3.0rg/2001/XMLSchema- instance" xsi:schemaLocation=" http://www. springframework.org/schema/beans http://www. springfranework.org/schema/beans/spring-beans.xsd">
|
Spring Bean Scopes: -> Bean Scope will decide how many objs should be created for Spring Bean class. > We have 4 types of scopes 4) singleton (default) 2) prototype 3) request 4) session*\ xmins:xsi="http://www.w3.org/2001/XMLSchem; xsi:schemaLocation=" http://mww.springframework.org/schema/beans http://www. springframework.org/schema/beans/spring-beans.xsd"> ‘
«
Ces © public class Test { public static void main(String{] args) { ApplicationContext ctxt = new ClassPathxmlApplicationContext("Beans.xm"); Car c1 = ctxt.getBean(Car.class); Ic1.drive(); ‘System. out.printin(cl.hashCode()); Car c2 = ctxt.getBean(Car.class); ‘System.out.printin(c2.hashCode());UTE-8"2> nttp://www. springframework.org/schema/beans" "http:/ Awww.w3.0rg/2001/XMLSchem: xsi:schemaLocation=" http://mww.springframework.org/schema/beans http://www. springframework.org/schema/beans/spring-beans.xsd">
‘
*\ public class Test { public static void main(Stringf] args) { ApplicationContext ctxt = new Cee eerie ClassPathxmlApplicationContext("‘Beans.xm"); ore ipeesie ens }public class Test { Public static void main(Stringl] args) { ‘ApplicationContext ctxt = new ClassPathXmlApplicationContext(""Beans.xml"); poor Soares Car ¢1 = ctxt.getBean(Car.class } eer eee ere ke ed eens "UTE-8"?> http://www.springframework.org/schema/beans” "http: //www.w3.org/2001/XMLSchema- instance” xsisschemaLocation=" http://www.springframework.org/schema/beans http://www. springframework.org/schema/beans/spring-beans.xsd">
\\ sfbeans>/ public class Test { public static void main(stringf} args) { ‘ApplicationContext ctxt = new ClassPathXmlApplicationContext(""Beans.xml"); Car cl = ctxt.getBean(Car.class); Merdrive(); System.out.printin(c1.hashCode()); Car c2 = ctxt.getBean(Car.class); ‘System.out.printin(c2.hashCode()); When user login---> one time session object will be created till user logout we will use the same session object (Singleton)ores Peer tenes Ree een cee ey eee ere eee) ec eee ne eed poe eens ea 2. For every customer do | need to create a Pete ea een ed pemeey) eee ‘Token will be same for ll the customer or Pee ones) CO een
You might also like
Spring by Durgesh
PDF
100% (1)
Spring by Durgesh
58 pages
Spring Annotations
PDF
No ratings yet
Spring Annotations
11 pages
Spring
PDF
No ratings yet
Spring
11 pages
Spring Interview Questions
PDF
No ratings yet
Spring Interview Questions
17 pages
611596936-Spring-by-durgesh
PDF
No ratings yet
611596936-Spring-by-durgesh
58 pages
Spring Notes
PDF
No ratings yet
Spring Notes
13 pages
12 Spring Boot Annotations
PDF
No ratings yet
12 Spring Boot Annotations
4 pages
Chapter 4C REST wz Jackson
PDF
No ratings yet
Chapter 4C REST wz Jackson
423 pages
What Is A Spring Bean?: Org - Springframework.Beans Org - Springframework.Context Beanfactory Applicationcontext Beanfactory
PDF
No ratings yet
What Is A Spring Bean?: Org - Springframework.Beans Org - Springframework.Context Beanfactory Applicationcontext Beanfactory
6 pages
Spring Core
PDF
No ratings yet
Spring Core
8 pages
Unit 5 Spring Framework
PDF
No ratings yet
Unit 5 Spring Framework
49 pages
MVC Spring Application Setup:: Dependencies
PDF
No ratings yet
MVC Spring Application Setup:: Dependencies
9 pages
Spring Framework 3.1
PDF
No ratings yet
Spring Framework 3.1
284 pages
Spring Annotations
PDF
No ratings yet
Spring Annotations
19 pages
Inversion_of_Control_with_Example
PDF
No ratings yet
Inversion_of_Control_with_Example
3 pages
For Example: Suppose We Have An Object Employee and It Has A Dependency On
PDF
100% (1)
For Example: Suppose We Have An Object Employee and It Has A Dependency On
3 pages
Spring Framework
PDF
No ratings yet
Spring Framework
11 pages
Spring Day 2
PDF
No ratings yet
Spring Day 2
3 pages
Spring Boot Framework
PDF
No ratings yet
Spring Boot Framework
11 pages
bio
PDF
No ratings yet
bio
21 pages
Spring Core
PDF
No ratings yet
Spring Core
6 pages
Spring Interview Questions With Answers
PDF
No ratings yet
Spring Interview Questions With Answers
10 pages
Unit-5-Spring Framework
PDF
No ratings yet
Unit-5-Spring Framework
37 pages
SBMS 6am 24112022
PDF
No ratings yet
SBMS 6am 24112022
3 pages
Spring-Quick-Revision
PDF
No ratings yet
Spring-Quick-Revision
6 pages
What Is Spring
PDF
No ratings yet
What Is Spring
6 pages
5 6312334183918208124
PDF
No ratings yet
5 6312334183918208124
26 pages
Spring Framework Notes
PDF
No ratings yet
Spring Framework Notes
131 pages
Unit - 5 Spring Framework and SpringBoot Sachin Sir
PDF
No ratings yet
Unit - 5 Spring Framework and SpringBoot Sachin Sir
39 pages
SpringInAction CraigWalls
PDF
No ratings yet
SpringInAction CraigWalls
44 pages
Spring
PDF
No ratings yet
Spring
6 pages
java code interview
PDF
No ratings yet
java code interview
9 pages
Spring IoC
PDF
No ratings yet
Spring IoC
48 pages
Spring
PDF
No ratings yet
Spring
7 pages
Spring DI&IOC
PDF
No ratings yet
Spring DI&IOC
38 pages
1. SPRING BOOT WORKSHOP 2 days productapp with sec jwt cheetsheet
PDF
No ratings yet
1. SPRING BOOT WORKSHOP 2 days productapp with sec jwt cheetsheet
43 pages
What is Spring Framework-2
PDF
No ratings yet
What is Spring Framework-2
11 pages
Spring Interview Questions
PDF
No ratings yet
Spring Interview Questions
26 pages
Java
PDF
No ratings yet
Java
5 pages
Spring Bean Scope
PDF
No ratings yet
Spring Bean Scope
6 pages
Spring
PDF
No ratings yet
Spring
13 pages
Spring and Springboot
PDF
No ratings yet
Spring and Springboot
12 pages
SPRING_MyNote-All
PDF
No ratings yet
SPRING_MyNote-All
15 pages
SpringCore - Session2
PDF
No ratings yet
SpringCore - Session2
8 pages
Most Imp Spring Interview QN and Ans
PDF
No ratings yet
Most Imp Spring Interview QN and Ans
15 pages
Introduction To Spring Framework: by Akhilesh Jaiswal
PDF
No ratings yet
Introduction To Spring Framework: by Akhilesh Jaiswal
25 pages
Java Unit V
PDF
No ratings yet
Java Unit V
93 pages
unit-5 (3)
PDF
No ratings yet
unit-5 (3)
51 pages
Spring Core
PDF
No ratings yet
Spring Core
5 pages
Spring
PDF
No ratings yet
Spring
51 pages
Public Class Customer (Private Person Person Private Int Type
PDF
No ratings yet
Public Class Customer (Private Person Person Private Int Type
20 pages
28.spring 5
PDF
No ratings yet
28.spring 5
142 pages
Spring Core&Boot
PDF
No ratings yet
Spring Core&Boot
40 pages
ChatGPT - Shared Content
PDF
No ratings yet
ChatGPT - Shared Content
105 pages
Introduction To The Spring Framework Ajit Koti
PDF
No ratings yet
Introduction To The Spring Framework Ajit Koti
46 pages
Spring Notes (Unit-5)
PDF
No ratings yet
Spring Notes (Unit-5)
14 pages
SpringAndSpringBootinterviewqsns
PDF
No ratings yet
SpringAndSpringBootinterviewqsns
8 pages
Rohit InterView Guide - Java Developer
PDF
No ratings yet
Rohit InterView Guide - Java Developer
24 pages