spring-ioc.pptx

AshokGupta647838 7 views 13 slides Sep 04, 2023
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

Spring IOC


Slide Content

Spring Inversion of Control

1)Coach of base ball will provide the work out time 2)My app can be configured 3)I can add any other coach will provide me the work out time 4)cricket , hockey, any other Class BaseBall Class Coach

Ideal Solution My App BaseballCoach give me a “Coach” object HockeyCoach CricketCoach Object Fa c tory configuration

Spring Container My App BaseballCoach give me a “Coach” object HockeyCoach CricketCoach Object Fa c tory configuration Spring

Spring Container • Primary functions • Create and manage objects (Inversion of Control) • Inject object’s dependencies (Dependency Injection) Object Fa c tory Spring

Configuring Spring Container • XML configuration file (legacy, but most legacy apps still use this) • Java Annotations (modern) • Java Source Code (modern)

Spring Development Process Configure your Spring Beans Create a Spring Container Retrieve Beans from Spring Container Ste p -B y-Ste p

Step 1: Configure your Spring Beans < beans … > < bean id = "myCoach" class = " com.springdemo.BaseballCoach " > </ bean > </ beans > File: applicationContext.xml

Step 2: Create a Spring Container Spring container is generically known as ApplicationContext Specialized implementations ClassPathXmlApplicationContext AnnotationConfigApplicationContext GenericWebApplicationContext others … Object Fa c tory Spring

Step 2: Create a Spring Container ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext.xml" );

My App BaseballCoach give me a “Coach” object HockeyCoach CricketCoach Object Fa c tory configuration Step 3: Retrieve Beans from Container Spring

Step 3: Retrieve Beans from Container // create a spring container ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext.xml" ); // retrieve bean from spring container Coach theCoach = context .getBean( "myCoach" , Coach. class ); File: applicationContext.xml < bean id = "myCoach" class = " com.springdemo.BaseballCoach " > </ bean >

What is a Spring Bean? A "Spring Bean" is simply a Java object. When Java objects are created by the Spring Container, then Spring refers to them as "Spring Beans". Spring Beans are created from normal Java classes .... just like Java objects. File: applicationContext.xml < bean id = "myCoach" class = " com.springdemo.BaseballCoach " > </ bean >
Tags