SlideShare una empresa de Scribd logo
1 de 10
Introduction to
Spring Framework
CSE424: Aspect and Service Oriented Software Systems
Section: 2 “Starter application”
Bootstrapping the application
 Spring Boot starter dependencies are special in that they typically don’t
have any library code themselves, but instead transitively pull in other
libraries.
 These starter dependencies offer three primary benefits:
 Your build file will be significantly smaller and easier to manage because
you won’t need to declare a dependency on every library you might need.
 You’re able to think of your dependencies in terms of what capabilities
they provide, rather than in terms of library names
 You’re freed from the burden of worry about library versions. You can
trust that for a given version of Spring Boot, the versions of the libraries
brought in transitively will be compatible.
 You only need to worry about which version of Spring Boot you’re
using.
Bootstrapping the application
 Setting the dependencies within the pom.xml file
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>6.0.5</version>
</dependency>
Bootstrapping the application
 Create a new classes “Car” , “Bike” and an interface
package com.maven.lab1;
import org.springframework.stereotype.Component;
@Component
public class Car implements Vehicle{
public void drive() {
System.out.println(“This is the car class");
}
}
Bootstrapping the application
@ Component is responsible for some operations.
Spring framework provides three other specific annotations to be used when
marking a class as Component.
 Service: Denotes that the class provides some services. Our utility classes can
be marked as Service classes.
 Repository: This annotation indicates that the class deals with CRUD
operations, usually it’s used with DAO implementations that deal with database
tables.
 Controller: Mostly used with web applications or REST web services to specify
that the class is a front controller and responsible to handle user request and
return appropriate response.
Note that all these four annotations are in package org.springframework.stereotype
and part of spring-context jar.
Bootstrapping the application
 Create a new object of the class Car in the main App.java
package com.maven.lab1;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args )
{
Car car = new Car();
car.drive();
}
}
Bootstrapping the application
 Instead of creating an object from each class and using a controller to control the whole system using a
beanFactory
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>6.0.5</version>
</dependency>
 And the App.java file will be updated as follows:
package com.maven.lab1;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args )
{
ApplicationContext context = new
ClassPathXmlApplicationContext("spring.xml");
Vehicle obj = (Vehicle) context.getBean("vehicle");
obj.drive();}}
Bootstrapping the application
ClassPathXmlApplicationContext("spring.xml");
 A new xml file that would be used to control the whole application through the use of beans
 The contents of this xml file :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.maven.lab1"></context:component-
scan>
<bean id="vehicle" class="com.maven.lab1.Car"></bean>
</bean>
</beans>
Task
Using the previous information, Can you control and change the main application to print
the contents of the Bike class instead of Car class?
Getting started
 To start our first Aspect project we need:
1. Dependent class files
2. A new xml file to remove the dependency
 Bean dependencies:
 In a new xml file add the beans
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/co
ntext"
xsi:schemaLocation="http://www.springframework.org/sche
ma/beans
http://www.springframework.org/schema/beans/spring-
beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-
context.xsd">

Más contenido relacionado

Similar a Introduction to Spring sec2.pptx

Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
Syed Shahul
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
Nilesh Bangar
 

Similar a Introduction to Spring sec2.pptx (20)

spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malav
 
Flask
FlaskFlask
Flask
 
Maven in mulesoft
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring boot
Spring bootSpring boot
Spring boot
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: Information
 
Spring 2
Spring 2Spring 2
Spring 2
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Spring hibernate tutorial
Spring hibernate tutorialSpring hibernate tutorial
Spring hibernate tutorial
 
Maven
MavenMaven
Maven
 
cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
 
Exploring the Exciting Features of Spring Boot 3.1.pdf
Exploring the Exciting Features of Spring Boot 3.1.pdfExploring the Exciting Features of Spring Boot 3.1.pdf
Exploring the Exciting Features of Spring Boot 3.1.pdf
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
 
Session 1
Session 1Session 1
Session 1
 

Más de NourhanTarek23 (15)

CSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfCSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdf
 
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdfCSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
 
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxCSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Lect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptLect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.ppt
 
Software engineering.pptx
Software engineering.pptxSoftware engineering.pptx
Software engineering.pptx
 
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives  IOT and Big Data Era.pptxLect01 Computers Impact on Our lives  IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
 
section5.pptx
section5.pptxsection5.pptx
section5.pptx
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
 
AOP sec3.pptx
AOP sec3.pptxAOP sec3.pptx
AOP sec3.pptx
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
QoS.pptx
QoS.pptxQoS.pptx
QoS.pptx
 
’mobile ip.pptx
’mobile ip.pptx’mobile ip.pptx
’mobile ip.pptx
 
Problem set 3-solution.pptx
Problem set 3-solution.pptxProblem set 3-solution.pptx
Problem set 3-solution.pptx
 

Último

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Introduction to Spring sec2.pptx

  • 1. Introduction to Spring Framework CSE424: Aspect and Service Oriented Software Systems Section: 2 “Starter application”
  • 2. Bootstrapping the application  Spring Boot starter dependencies are special in that they typically don’t have any library code themselves, but instead transitively pull in other libraries.  These starter dependencies offer three primary benefits:  Your build file will be significantly smaller and easier to manage because you won’t need to declare a dependency on every library you might need.  You’re able to think of your dependencies in terms of what capabilities they provide, rather than in terms of library names  You’re freed from the burden of worry about library versions. You can trust that for a given version of Spring Boot, the versions of the libraries brought in transitively will be compatible.  You only need to worry about which version of Spring Boot you’re using.
  • 3. Bootstrapping the application  Setting the dependencies within the pom.xml file <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>6.0.5</version> </dependency>
  • 4. Bootstrapping the application  Create a new classes “Car” , “Bike” and an interface package com.maven.lab1; import org.springframework.stereotype.Component; @Component public class Car implements Vehicle{ public void drive() { System.out.println(“This is the car class"); } }
  • 5. Bootstrapping the application @ Component is responsible for some operations. Spring framework provides three other specific annotations to be used when marking a class as Component.  Service: Denotes that the class provides some services. Our utility classes can be marked as Service classes.  Repository: This annotation indicates that the class deals with CRUD operations, usually it’s used with DAO implementations that deal with database tables.  Controller: Mostly used with web applications or REST web services to specify that the class is a front controller and responsible to handle user request and return appropriate response. Note that all these four annotations are in package org.springframework.stereotype and part of spring-context jar.
  • 6. Bootstrapping the application  Create a new object of the class Car in the main App.java package com.maven.lab1; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main( String[] args ) { Car car = new Car(); car.drive(); } }
  • 7. Bootstrapping the application  Instead of creating an object from each class and using a controller to control the whole system using a beanFactory <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>6.0.5</version> </dependency>  And the App.java file will be updated as follows: package com.maven.lab1; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main( String[] args ) { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); Vehicle obj = (Vehicle) context.getBean("vehicle"); obj.drive();}}
  • 8. Bootstrapping the application ClassPathXmlApplicationContext("spring.xml");  A new xml file that would be used to control the whole application through the use of beans  The contents of this xml file : <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.maven.lab1"></context:component- scan> <bean id="vehicle" class="com.maven.lab1.Car"></bean> </bean> </beans>
  • 9. Task Using the previous information, Can you control and change the main application to print the contents of the Bike class instead of Car class?
  • 10. Getting started  To start our first Aspect project we need: 1. Dependent class files 2. A new xml file to remove the dependency  Bean dependencies:  In a new xml file add the beans <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/co ntext" xsi:schemaLocation="http://www.springframework.org/sche ma/beans http://www.springframework.org/schema/beans/spring- beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring- context.xsd">