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)
21 views
Spring
Spring module
Uploaded by
varun varun
AI-enhanced title
Copyright
© © All Rights Reserved
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)
21 views
Spring
Spring module
Uploaded by
varun varun
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Spring (1) For Later
Carousel Previous
Carousel Next
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
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6129)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (934)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carre
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel