SlideShare a Scribd company logo
1 of 18
A Complete Spring Boot Course for beginners
https://spring.io/
PAGE 1
Sufyan Sattar
Software Engineer
sufyan.sattar@tkxel.com
Course
Outline
Introduction to Spring Boot and Background
Web Services (SOAP and Restful)
JPA/Hibernate and Custom SQL Queries
H2 Database (In memory database)
PostgreSQL and MySQL
PAGE 2
Introduction to Spring Boot
 It is an application framework used for developing Enterprise Applications.
 It makes programming Java quicker, easier, and safer for everybody.
 It provides a flexible way to configure Java Beans, XML configurations, and Database Transactions.
It provides powerful batch processing and manages REST endpoints. In Spring Boot, everything is
auto-configured; no manual configurations are needed.
 Termimology:
 Spring Initializer (https://start.spring.io/)
 Starter Projects
 Auto Configuration
 Actuators
 Developer Tools (DevTools)
PAGE 3
 Setting up Spring Web projects was not easy
 Define Maven Dependencies and manage versions for the framework (spring web_mvc, Jackson)
 Define web.xml (src/main/webapp/WEB_INF/web.xml)
 Define front controller for spring framework (Dispatcher Servlets)
 Define a Spring content.xml (src/main/webapp/WEB_INF/todo_servlet.xml)
 Define all beans
 Define component scan
 Install Tomcat or another web server like Glassfish.
 Deploy and run the application in Tomcat
PAGE 4
World Before Spring Boot
 Spring Boot Starter Projects
 It helps you get the project up and running quickly.
 Web Applications (Spring boot starter web)
 Rest API (Spring boot starter web)
 Talk to database using JPA (spring boot starter data JPA)
 Talk to database using JDBC (spring boot starter JDBC)
 Spring Boot Auto Configurations
 It provides a basic configuration to run your app using the framework defined in maven dependencies.
 We can override our own configuration
 Auto configuration is decided based on which framework is in the classpath
 E.g. (spring boot starter web)
 Dispatch Servlet
 Embeded Servlets Container – Tomcat is the default server
 Default Error Page
 Bean to JSON conversion
PAGE 5
How does Spring Boot do its magic?
 Monitor and manage your application in your production.
 Provides a number of endpoints:-
 Beans – Complete the list of Spring beans in your app
 Health – Application health information
 Metrics – Application metrics
 Mapping – Details around Request Mapping
PAGE 6
Spring Boot - Actuators
 Increase developer productivity
 Save timing
 Only local machine or debug variant
Spring Boot - Dev Tools
PAGE 7
Spring Framework vs Spring Boot
 Spring Framework
 The Spring framework provides comprehensive infrastructure support for developing Java applications.
 It's packed with some nice features like Dependency Injection, and out-of-the-box modules like:
 Spring JDBC
 Spring MVC
 Spring Security
 Spring ORM
 Spring Test
 Spring Boot
 Spring Boot is basically an extension of the Spring framework, which eliminates the boilerplate configurations
required for setting up a Spring application.
 Here are just a few of the features in Spring Boot:
 Opinionated ‘starter' dependencies to simplify the build and application configuration
 Embeded Server to avoid complexity in application deployment
 Metrics, Health checks, and external configuration
 Automatic config for Spring functionality
Web Services
 Design for machine-to-machine or application-to-application interaction.
 Should be interoperable – Not platform dependent
 Should allow communication over a network
Web Service Definition
Request/Response Format Request Structure Response Structure Endpoint
(XML/JSON)
Note
 Dispatcher Servlets handle the request/response
 Spring boot auto configuration handle/configure dispatcher servlets
 Jackson converts the Java Bean to JSON and vice versa
PAGE 8
PAGE 9
Web Service Task
 Social Media Application Usecase : User ---> Post
 Retrieve all users GetRequest /users
 Create a user PostRequest /users
 Retrieve a specific user GetRequest /users{id}
 Delete a user DeleteRequest /users{id}
1. Create a Controller. @RestController
2. Create methods for API and annotate with
1. @GetMapping
2. @PostMapping
3. @PutMapping
4. @DeleteMapping
PAGE 10
Web Service Topics
 HATEOAS (Hyper Media as the Engine of Application State)
 HATEOAS will add value to you API when used by client. The links provided by HATEOAS gives you the possibilities to
different parts (resources) of your API without needing to hardcore those links in your apps client code.
 We use WebMvcLinkBuilder and link any method/API of our
controller in the response.
 E.g. I request http://localhost:8080/jpa/users/1/posts/1
 Exception Handling
 Give a proper response to the user when an exception occurs with the status code.
 We can use ResponseEntityExceptionHandler to provide centralized exception handling across all @RequestMapping
methods through @ExceptionHandler methods.
PAGE 11
Web Service Topics
 Validation for Rest API
 We can add @Valid to validate our request
 @Sized(min=2) @Email @Past
 We just place annotation to the variable
 Internationalization for Restful Services
 We create different resources file w.r.t languages e.g: messages_fr.properties.
 In messages.properties file we write string in different language.
 Content Negotiation
 We can implement XML support in out Restful API.
 Client will sent Accept Header with application/xml value.
PAGE 12
Web Service Topics
 Swagger UI
 baseurl/swagger-ui/index.html
 OpenAPI create all the documentation of your Restful API in our application
 Swagger UI gets that data and represents in GUI
 OpenAPI definition: baseurl/v3/api-docs
 Monitory API with Spring Boot Actuators
 base_url/actuator
 We can manual configuration by adding some lines
 in application.properties file
 HAL Explorer
 Visualizing all API
 Its show all links in visual format
 You can also see HATEOAS links in visual formats
 base_url/explorer/
PAGE 13
Web Service Topics
 Filtering
 Static Filtering
 Just place @JsonIgnore above the variable
 You can also place above class name and add multiple parameter name
 Dynamic Filtering
 When you hide/show data in response w.r.t to response
 We use SimpleBeanPropertyFilter, FilterProvider, and MappingJacksonValue
 Versioning
 Url versioning
 Params versioning
 Customer Header versioning
 Produces versioning (mine-type versioning)
PAGE 14
Web Service Topics
 Security
 After Enable security web services will return 401 unauthorized status.
 Request all API with basic Auth (username=user and password=from console)
 Add configuration for static password not change when server restart
 security.username=username , security.password=password
JPA/Hibernate and Custom Query
 JPA is the specification and define the way to manage relational database using Java Objects
 Hibernate is the implementation of Java Persistence API. It is the ORM tool to persist Java objects
into relational database
 Implementation/Annotations:
 @Entity
 @Table(name=“employee”)
 @Column(name=“first_name”)
 EmptyConstructor
 All Argument Constructor
 Setter/Getter
 @OneToMany(mappedBy=“user”, cascade=Cascade.ALL)
 @ManyToOne()
 @JoinColoum
 @Id
 @GeneratedValue(strategy= GenerationType.IDENTITY)
 @Repository (interface UserRepo implement JpaRepository<User, Integer>)
PAGE 15
JPA/Hibernate and Custom Query
 JPA Repository:
 Its interface having default storage methods like save(), findAll(); findBtId(), DeleteById() etc.
 Its provides us the ORM for storing data into relational database.
 We can also write custom query for fetching data from database.
 JPA provided us @Query annotation.
 Create interface and implement JpaRepository<Object, Integer>)
 Inside repo you can write function and custom query
 Custom Query:
@Query(“SELECT * FROM posts WHERE user_id=:user_id AND id=:post_id”, nativeQuery=true)
 Post getPostDetailsOfSpecifcUser(
@Param(“user_id”) Integer user_id,
@Param(“post_id”) Integer post_id
);
PAGE 16
H2 Database
 H2 is inmemory database provided by Spring Boot.
 H2 database name randomly generated each time you restart the run or run application.
 We can make it constant by manual configuration:
 Spring.datasource.url=“jdbc:h2:mem:mytestdb”
 Sometime we need more fined grained control over tha database alterations and that why we create
data.sql and schema.sql
 data.sql:- We rely on default schema created by Hibernate/JPA. We add data into data.sql by writing SQL
queries into data.sql file
 schema.sql:- We don`t rely on default schema creation mechanism. We create own schema i.e table and
coloums etc. Spring will pickup this file and create schema
 Note: Script base initialization i.e through data.sql and schema.sql, and hibernate default initialization
together can cause some issues.
 We disable hibernate automatic schema creations with manual configuration.
 spring.jpa.hibernate.ddl-auto=none
 If you want to use both hibernate automatic creation schema and script based schema creation and data
population. You can use
 spring.jpa.defer-datasource-initialization=true
 Script base initialization is perform by default only for embeded databases.
PAGE 17
PostgreSQL and MySQL with Spring Boot
 Configuration with PostgreSQL
 spring.datasource.url=jdbc:postgresql://localhost:5432/employees
 spring.datasource.username=postgres
 spring.datasource.password=admin
 spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
 Configuration with MySQL
 spring.datasource.url=jdbc:mysql://localhost:3306/employees
 spring.datasource.username=root
 spring.datasource.password=admin
 spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
PAGE 18

More Related Content

Similar to SpringBootCompleteBootcamp.pptx

Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfLuca Mattia Ferrari
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Dh2 Apps Training Part2
Dh2   Apps Training Part2Dh2   Apps Training Part2
Dh2 Apps Training Part2jamram82
 
Module 6 _ Spring Boot for java application to begin
Module 6 _ Spring Boot for java application to beginModule 6 _ Spring Boot for java application to begin
Module 6 _ Spring Boot for java application to beginDeepakprasad838637
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Kazuyuki Kawamura
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introductionCommit University
 
Deploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineDeploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineAlexander Zamkovyi
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework Rohit Kelapure
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)Hendrik Ebbers
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvcGuo Albert
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 

Similar to SpringBootCompleteBootcamp.pptx (20)

JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Dh2 Apps Training Part2
Dh2   Apps Training Part2Dh2   Apps Training Part2
Dh2 Apps Training Part2
 
Jdbc
JdbcJdbc
Jdbc
 
Module 6 _ Spring Boot for java application to begin
Module 6 _ Spring Boot for java application to beginModule 6 _ Spring Boot for java application to begin
Module 6 _ Spring Boot for java application to begin
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Deploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineDeploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App Engine
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Aqua presentation
Aqua presentationAqua presentation
Aqua presentation
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 

Recently uploaded

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

SpringBootCompleteBootcamp.pptx

  • 1. A Complete Spring Boot Course for beginners https://spring.io/ PAGE 1 Sufyan Sattar Software Engineer sufyan.sattar@tkxel.com
  • 2. Course Outline Introduction to Spring Boot and Background Web Services (SOAP and Restful) JPA/Hibernate and Custom SQL Queries H2 Database (In memory database) PostgreSQL and MySQL PAGE 2
  • 3. Introduction to Spring Boot  It is an application framework used for developing Enterprise Applications.  It makes programming Java quicker, easier, and safer for everybody.  It provides a flexible way to configure Java Beans, XML configurations, and Database Transactions. It provides powerful batch processing and manages REST endpoints. In Spring Boot, everything is auto-configured; no manual configurations are needed.  Termimology:  Spring Initializer (https://start.spring.io/)  Starter Projects  Auto Configuration  Actuators  Developer Tools (DevTools) PAGE 3
  • 4.  Setting up Spring Web projects was not easy  Define Maven Dependencies and manage versions for the framework (spring web_mvc, Jackson)  Define web.xml (src/main/webapp/WEB_INF/web.xml)  Define front controller for spring framework (Dispatcher Servlets)  Define a Spring content.xml (src/main/webapp/WEB_INF/todo_servlet.xml)  Define all beans  Define component scan  Install Tomcat or another web server like Glassfish.  Deploy and run the application in Tomcat PAGE 4 World Before Spring Boot
  • 5.  Spring Boot Starter Projects  It helps you get the project up and running quickly.  Web Applications (Spring boot starter web)  Rest API (Spring boot starter web)  Talk to database using JPA (spring boot starter data JPA)  Talk to database using JDBC (spring boot starter JDBC)  Spring Boot Auto Configurations  It provides a basic configuration to run your app using the framework defined in maven dependencies.  We can override our own configuration  Auto configuration is decided based on which framework is in the classpath  E.g. (spring boot starter web)  Dispatch Servlet  Embeded Servlets Container – Tomcat is the default server  Default Error Page  Bean to JSON conversion PAGE 5 How does Spring Boot do its magic?
  • 6.  Monitor and manage your application in your production.  Provides a number of endpoints:-  Beans – Complete the list of Spring beans in your app  Health – Application health information  Metrics – Application metrics  Mapping – Details around Request Mapping PAGE 6 Spring Boot - Actuators  Increase developer productivity  Save timing  Only local machine or debug variant Spring Boot - Dev Tools
  • 7. PAGE 7 Spring Framework vs Spring Boot  Spring Framework  The Spring framework provides comprehensive infrastructure support for developing Java applications.  It's packed with some nice features like Dependency Injection, and out-of-the-box modules like:  Spring JDBC  Spring MVC  Spring Security  Spring ORM  Spring Test  Spring Boot  Spring Boot is basically an extension of the Spring framework, which eliminates the boilerplate configurations required for setting up a Spring application.  Here are just a few of the features in Spring Boot:  Opinionated ‘starter' dependencies to simplify the build and application configuration  Embeded Server to avoid complexity in application deployment  Metrics, Health checks, and external configuration  Automatic config for Spring functionality
  • 8. Web Services  Design for machine-to-machine or application-to-application interaction.  Should be interoperable – Not platform dependent  Should allow communication over a network Web Service Definition Request/Response Format Request Structure Response Structure Endpoint (XML/JSON) Note  Dispatcher Servlets handle the request/response  Spring boot auto configuration handle/configure dispatcher servlets  Jackson converts the Java Bean to JSON and vice versa PAGE 8
  • 9. PAGE 9 Web Service Task  Social Media Application Usecase : User ---> Post  Retrieve all users GetRequest /users  Create a user PostRequest /users  Retrieve a specific user GetRequest /users{id}  Delete a user DeleteRequest /users{id} 1. Create a Controller. @RestController 2. Create methods for API and annotate with 1. @GetMapping 2. @PostMapping 3. @PutMapping 4. @DeleteMapping
  • 10. PAGE 10 Web Service Topics  HATEOAS (Hyper Media as the Engine of Application State)  HATEOAS will add value to you API when used by client. The links provided by HATEOAS gives you the possibilities to different parts (resources) of your API without needing to hardcore those links in your apps client code.  We use WebMvcLinkBuilder and link any method/API of our controller in the response.  E.g. I request http://localhost:8080/jpa/users/1/posts/1  Exception Handling  Give a proper response to the user when an exception occurs with the status code.  We can use ResponseEntityExceptionHandler to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods.
  • 11. PAGE 11 Web Service Topics  Validation for Rest API  We can add @Valid to validate our request  @Sized(min=2) @Email @Past  We just place annotation to the variable  Internationalization for Restful Services  We create different resources file w.r.t languages e.g: messages_fr.properties.  In messages.properties file we write string in different language.  Content Negotiation  We can implement XML support in out Restful API.  Client will sent Accept Header with application/xml value.
  • 12. PAGE 12 Web Service Topics  Swagger UI  baseurl/swagger-ui/index.html  OpenAPI create all the documentation of your Restful API in our application  Swagger UI gets that data and represents in GUI  OpenAPI definition: baseurl/v3/api-docs  Monitory API with Spring Boot Actuators  base_url/actuator  We can manual configuration by adding some lines  in application.properties file  HAL Explorer  Visualizing all API  Its show all links in visual format  You can also see HATEOAS links in visual formats  base_url/explorer/
  • 13. PAGE 13 Web Service Topics  Filtering  Static Filtering  Just place @JsonIgnore above the variable  You can also place above class name and add multiple parameter name  Dynamic Filtering  When you hide/show data in response w.r.t to response  We use SimpleBeanPropertyFilter, FilterProvider, and MappingJacksonValue  Versioning  Url versioning  Params versioning  Customer Header versioning  Produces versioning (mine-type versioning)
  • 14. PAGE 14 Web Service Topics  Security  After Enable security web services will return 401 unauthorized status.  Request all API with basic Auth (username=user and password=from console)  Add configuration for static password not change when server restart  security.username=username , security.password=password
  • 15. JPA/Hibernate and Custom Query  JPA is the specification and define the way to manage relational database using Java Objects  Hibernate is the implementation of Java Persistence API. It is the ORM tool to persist Java objects into relational database  Implementation/Annotations:  @Entity  @Table(name=“employee”)  @Column(name=“first_name”)  EmptyConstructor  All Argument Constructor  Setter/Getter  @OneToMany(mappedBy=“user”, cascade=Cascade.ALL)  @ManyToOne()  @JoinColoum  @Id  @GeneratedValue(strategy= GenerationType.IDENTITY)  @Repository (interface UserRepo implement JpaRepository<User, Integer>) PAGE 15
  • 16. JPA/Hibernate and Custom Query  JPA Repository:  Its interface having default storage methods like save(), findAll(); findBtId(), DeleteById() etc.  Its provides us the ORM for storing data into relational database.  We can also write custom query for fetching data from database.  JPA provided us @Query annotation.  Create interface and implement JpaRepository<Object, Integer>)  Inside repo you can write function and custom query  Custom Query: @Query(“SELECT * FROM posts WHERE user_id=:user_id AND id=:post_id”, nativeQuery=true)  Post getPostDetailsOfSpecifcUser( @Param(“user_id”) Integer user_id, @Param(“post_id”) Integer post_id ); PAGE 16
  • 17. H2 Database  H2 is inmemory database provided by Spring Boot.  H2 database name randomly generated each time you restart the run or run application.  We can make it constant by manual configuration:  Spring.datasource.url=“jdbc:h2:mem:mytestdb”  Sometime we need more fined grained control over tha database alterations and that why we create data.sql and schema.sql  data.sql:- We rely on default schema created by Hibernate/JPA. We add data into data.sql by writing SQL queries into data.sql file  schema.sql:- We don`t rely on default schema creation mechanism. We create own schema i.e table and coloums etc. Spring will pickup this file and create schema  Note: Script base initialization i.e through data.sql and schema.sql, and hibernate default initialization together can cause some issues.  We disable hibernate automatic schema creations with manual configuration.  spring.jpa.hibernate.ddl-auto=none  If you want to use both hibernate automatic creation schema and script based schema creation and data population. You can use  spring.jpa.defer-datasource-initialization=true  Script base initialization is perform by default only for embeded databases. PAGE 17
  • 18. PostgreSQL and MySQL with Spring Boot  Configuration with PostgreSQL  spring.datasource.url=jdbc:postgresql://localhost:5432/employees  spring.datasource.username=postgres  spring.datasource.password=admin  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect  Configuration with MySQL  spring.datasource.url=jdbc:mysql://localhost:3306/employees  spring.datasource.username=root  spring.datasource.password=admin  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver PAGE 18