SlideShare uma empresa 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">

Mais conteúdo relacionado

Semelhante 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
 

Semelhante 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
 

Mais 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

Último (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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
 
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.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

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">