Spring boot

Spring Boot
Code with 0% Configuration
Gyenendra Yadav
Jindal InfoSolutions
Introduction – pivotal Say…
 Spring Boot makes it easy to create stand-alone,
production-grade Spring based Applications that you can
“just run”. We take an opinionated view of the Spring
platform and third-party libraries so you can get started
with minimum fuss. Most Spring Boot applications need
very little Spring configuration.
 You can use Spring Boot to create Java applications that
can be started using java -jar or more traditional war
deployments. We also provide a command line tool that
runs “spring scripts”.
Spring boot
WHY We Need Spring Boot?
 Spring Boot is next generation attempt to easy spring setup.
 Spring Boot’s main benefit is configuring the resources based on
what it finds in the classpath.
 If your Maven POM includes JPA dependencies and a MYSQL
driver, then Spring Boot will setup a persistence unit based on
MySQL. If you’ve added a web dependency, then you will get
Spring MVC configured with defaults.
 When we talk about defaults, Spring Boot has its own opinions.
If you are not specifying the details, it will use its own default
configurations. If you want persistence, but don’t specify
anything else in your POM file, then Spring Boot configures
Hibernate as a JPA provider with an HSQLDB database.
primary goals
 To provide a radically faster and widely accessible getting
started development experience for all Spring
development. Since spring community has evolved so big,
it is time to re-invent the way how spring applications are
deployed in much quicker turn around time.
 To be get started so quickely using the default values
which are supported out of the box in the Spring Boot
configurations.
 To provide bunch of non-functional features/solutions that
are very much common to large scale projects (e.g.
embedded servers, security, metrics, health checks,
externalized configuration).
What Spring Boot brings to the table ?
 Convention over configuration
 Standardization for Microservices
 Integrated Server for Development
 Cloud Support
 Adapt & Support for 3rd Party Library
Spring Boot Components
Spring Boot Auto Configure
 Module to auto configure a wide range of Spring projects.
 It will detect availability of certain frameworks (Spring
Batch, Spring Data JPA, Hibernate, JDBC).
 When detected it will try to auto configure that
framework with some sensible defaults, which in general
can be overridden by configuration in an
application.properties/yml(yaml-data serialization
language) file.
Spring Boot Core
The base for other modules, but it also provides
some functionality that can be used on its own, eg.
using command line arguments and YAML files as
Spring Environment property sources and
automatically binding environment properties to
Spring bean properties (with validation).
Spring Boot CLI
A command line interface, based on ruby, to
start/stop spring boot created applications.
Spring Boot Actuator
 This project, when added, will enable certain
enterprise features (Security, Metrics, Default
Error pages) to your application.
 As the auto configure module it uses auto
detection to detect certain frameworks/features
of your application. For an example, you can see
all the REST Services defined in a web application
using Actuator.
Spring Boot Starters
 Different quick start projects to include as a
dependency in your maven or gradle build file.
 It will have the needed dependencies for that
type of application.
 Currently there are many starter projects and
many more are expected to be added.
Spring Boot Tools
 The Maven and Gradle build tool as well as the
custom Spring Boot Loader (used in the single
executable jar/war) is included in this project.
How to use Spring Boot
 You can use spring initialize to create the initial setup. You can visit
either start.spring.io or use STS (Spring Tool Suite) Support available
in IDEA or Eclipse to choose all the Spring Boot Starters
 You need to also choose whether to use Maven or Gradle as the build
tool.
 If you are using start.spring.io, you need to then download the zip and
configure your workspace. Otherwise using your preferred IDE will
automatically create the required file in the workspace.
 Add your code as required
 You can either use mvn clean package or use IDEA or Eclipse to build
and create the jar file.
 By default the JAR would include integrated Tomcat server, so just by
executing the JAR you should be able to use your program.
Spring boot
Environment Setup for Eclipse
Spring boot
Spring boot
Create Project
 Goto Window Menu -> Perspective ->Spring
 Goto File Menu ->New -> Spring Starter Project
Spring boot
Spring boot
Spring boot
Spring boot
Spring boot
MyAppApplication Class
package com.apps;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyAppApplication {
public static void main(String[] args) {
SpringApplication.run(MyAppApplication.class, args);
}
}
@SpringBootApplication annotation
 @SpringBootApplication annotation
 Many Spring Boot developers always have their main class
annotated with @Configuration, @EnableAutoConfiguration and
@ComponentScan. Since these annotations are so frequently
used together (especially if you follow the best practices
above), Spring Boot provides a convenient
@SpringBootApplication alternative.
 The @SpringBootApplication annotation is equivalent to using
@Configuration, @EnableAutoConfiguration and
@ComponentScan with their default attributes:
SpringApplication.run()
 You need to run Application.run() because this method starts whole Spring
Framework. Code below integrates your main() with Spring Boot.
 public class SpringApplication extends Object
 Classes that can be used to bootstrap and launch a Spring application from a Java
main method. By default class will perform the following steps to bootstrap your
application:
 Create an appropriate ApplicationContext instance (depending on your classpath)
 Register a CommandLinePropertySource to expose command line arguments as Spring
properties
 Refresh the application context, loading all singleton beans
 Trigger any CommandLineRunner beans
 In most circumstances the static run(Object, String[]) method can be called
directly from your main method to bootstrap your application:
application.properties File
 spring.datasource.url=jdbc:mysql://localhost:3306/springboot
 spring.datasource.username=admin
 spring.datasource.password=admin
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 # Allows Hibernate to generate SQL optimized for a particular DBMS
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Di
alect
 # Number of ms to wait before throwing an exception if no connection
is available.
 spring.datasource.tomcat.max-wait=10000
 # Maximum no of active conn that can be allocated from this pool at the
same time.
 spring.datasource.tomcat.max-active=50
 # Validate the connection before borrowing it from the pool.
 spring.datasource.tomcat.test-on-borrow=true
Continue…….
 # Keep the connection alive if idle for a long time (needed in production)
 spring.datasource.dbcp.test-while-idle=true
 spring.datasource.dbcp.validation-query=SELECT 1
 # Naming strategy
 spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
 # Hibernate ddl auto (create, create-drop, update): with "update" the database
 # schema will be automatically updated accordingly to java entities found in
 # the project
 spring.jpa.hibernate.ddl-auto=update
 # Show or not log for each sql query
 spring.jpa.show-sql = true
Load Custom Application Context
package com.apps;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@ImportResource("applicationContext.xml")
public class MyAppApplication {
public static void main(String[] args) {
SpringApplication.run(MyAppApplication.class, args);
}
}
Spring boot
Thank you
 References
 http://docs.spring.io/spring-boot/docs/2.0.x-SNAPSHOT/reference/html/
 http://www.adeveloperdiary.com/java/spring-boot/an-introduction-to-spring-
boot/
 Assignment For you
 Configure yourself
 How to create jar for deployment on production server
1 de 32

Recomendados

Spring boot introduction por
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
7.7K visualizações36 slides
Spring boot por
Spring bootSpring boot
Spring bootsdeeg
26.6K visualizações25 slides
Spring boot Introduction por
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
3.1K visualizações26 slides
Xke spring boot por
Xke spring bootXke spring boot
Xke spring bootsourabh aggarwal
1.3K visualizações20 slides
Spring Boot in Action por
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
3K visualizações55 slides
Spring Boot por
Spring BootSpring Boot
Spring BootJiayun Zhou
2.5K visualizações110 slides

Mais conteúdo relacionado

Mais procurados

Spring boot - an introduction por
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
1.9K visualizações17 slides
Spring Boot por
Spring BootSpring Boot
Spring BootJaran Flaath
543 visualizações51 slides
Introduction to Spring Framework por
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
26K visualizações52 slides
Introduction to Spring Boot por
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootPurbarun Chakrabarti
1K visualizações18 slides
Introduction to Spring Boot! por
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
6.4K visualizações28 slides
Spring Boot por
Spring BootSpring Boot
Spring BootHongSeong Jeon
3.9K visualizações41 slides

Mais procurados(20)

Spring boot - an introduction por Jonathan Holloway
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway1.9K visualizações
Spring Boot por Jaran Flaath
Spring BootSpring Boot
Spring Boot
Jaran Flaath543 visualizações
Introduction to Spring Framework por Serhat Can
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can26K visualizações
Introduction to Spring Boot por Purbarun Chakrabarti
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti1K visualizações
Introduction to Spring Boot! por Jakub Kubrynski
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski6.4K visualizações
Spring Boot por HongSeong Jeon
Spring BootSpring Boot
Spring Boot
HongSeong Jeon3.9K visualizações
Introduction to spring boot por Santosh Kumar Kar
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar19.4K visualizações
Spring Framework por nomykk
Spring FrameworkSpring Framework
Spring Framework
nomykk1.9K visualizações
Spring Framework por tola99
Spring Framework  Spring Framework
Spring Framework
tola991.2K visualizações
Spring Framework - AOP por Dzmitry Naskou
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou8.4K visualizações
Spring - Part 1 - IoC, Di and Beans por Hitesh-Java
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java1.3K visualizações
Introduction to Spring Framework por Hùng Nguyễn Huy
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Hùng Nguyễn Huy528 visualizações
Java Spring Framework por Mehul Jariwala
Java Spring FrameworkJava Spring Framework
Java Spring Framework
Mehul Jariwala2.9K visualizações
Rediscovering Spring with Spring Boot(1) por Gunith Devasurendra
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra428 visualizações
Spring Framework - Core por Dzmitry Naskou
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou34.8K visualizações
Introduction to Spring Boot por Trey Howard
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard656 visualizações
Spring Boot por Pei-Tang Huang
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang4.3K visualizações
Connecting Connect with Spring Boot por Vincent Kok
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
Vincent Kok1.1K visualizações
Spring MVC por Aaron Schram
Spring MVCSpring MVC
Spring MVC
Aaron Schram2K visualizações

Similar a Spring boot

Spring boot jpa por
Spring boot jpaSpring boot jpa
Spring boot jpaHamid Ghorbani
915 visualizações19 slides
Building a Spring Boot Application - Ask the Audience! por
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!🎤 Hanno Embregts 🎸
917 visualizações21 slides
Springboot2 postgresql-jpa-hibernate-crud-example with test por
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testHyukSun Kwon
105 visualizações20 slides
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017) por
Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)🎤 Hanno Embregts 🎸
738 visualizações22 slides
Spring Boot Whirlwind Tour por
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind TourVMware Tanzu
463 visualizações19 slides
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf por
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfAppster1
3 visualizações36 slides

Similar a Spring boot(20)

Spring boot jpa por Hamid Ghorbani
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani915 visualizações
Building a Spring Boot Application - Ask the Audience! por 🎤 Hanno Embregts 🎸
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
🎤 Hanno Embregts 🎸917 visualizações
Springboot2 postgresql-jpa-hibernate-crud-example with test por HyukSun Kwon
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon105 visualizações
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017) por 🎤 Hanno Embregts 🎸
Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
🎤 Hanno Embregts 🎸738 visualizações
Spring Boot Whirlwind Tour por VMware Tanzu
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
VMware Tanzu463 visualizações
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf por Appster1
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster13 visualizações
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf por Appster1
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster12 visualizações
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018) por 🎤 Hanno Embregts 🎸
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
🎤 Hanno Embregts 🎸279 visualizações
Springboot2 postgresql-jpa-hibernate-crud-example por HyukSun Kwon
Springboot2 postgresql-jpa-hibernate-crud-exampleSpringboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-example
HyukSun Kwon47 visualizações
Spring Boot por Jaydeep Kale
Spring BootSpring Boot
Spring Boot
Jaydeep Kale38 visualizações
Spring boot vs spring framework razor sharp web applications por Katy Slemon
Spring boot vs spring framework razor sharp web applicationsSpring boot vs spring framework razor sharp web applications
Spring boot vs spring framework razor sharp web applications
Katy Slemon79 visualizações
1.introduction to java por Madhura Bhalerao
1.introduction to java1.introduction to java
1.introduction to java
Madhura Bhalerao203 visualizações
Spring boot for buidling microservices por Nilanjan Roy
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
Nilanjan Roy1.2K visualizações
Maven Introduction por Sandeep Chawla
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla21.1K visualizações
Google App Engine for Java por Lars Vogel
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
Lars Vogel3.7K visualizações
Spring framework por vietduc17
Spring frameworkSpring framework
Spring framework
vietduc17251 visualizações
How Spring Framework Really Works? por NexSoftsys
How Spring Framework Really Works?How Spring Framework Really Works?
How Spring Framework Really Works?
NexSoftsys564 visualizações

Último

Searching in Data Structure por
Searching in Data StructureSearching in Data Structure
Searching in Data Structureraghavbirla63
5 visualizações8 slides
Thermal aware task assignment for multicore processors using genetic algorithm por
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm IJECEIAES
31 visualizações12 slides
Design of machine elements-UNIT 3.pptx por
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptxgopinathcreddy
29 visualizações31 slides
MSA Website Slideshow (16).pdf por
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdfmsaucla
58 visualizações8 slides
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ... por
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...AltinKaradagli
6 visualizações16 slides
NEW SUPPLIERS SUPPLIES (copie).pdf por
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdfgeorgesradjou
14 visualizações30 slides

Último(20)

Searching in Data Structure por raghavbirla63
Searching in Data StructureSearching in Data Structure
Searching in Data Structure
raghavbirla635 visualizações
Thermal aware task assignment for multicore processors using genetic algorithm por IJECEIAES
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm
IJECEIAES31 visualizações
Design of machine elements-UNIT 3.pptx por gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy29 visualizações
MSA Website Slideshow (16).pdf por msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla58 visualizações
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ... por AltinKaradagli
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
Investigation of Physicochemical Changes of Soft Clay around Deep Geopolymer ...
AltinKaradagli6 visualizações
NEW SUPPLIERS SUPPLIES (copie).pdf por georgesradjou
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdf
georgesradjou14 visualizações
SPICE PARK DEC2023 (6,625 SPICE Models) por Tsuyoshi Horigome
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models)
Tsuyoshi Horigome17 visualizações
Instrumentation & Control Lab Manual.pdf por NTU Faisalabad
Instrumentation & Control Lab Manual.pdfInstrumentation & Control Lab Manual.pdf
Instrumentation & Control Lab Manual.pdf
NTU Faisalabad 5 visualizações
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa... por ijseajournal
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
Taking out the Trash (And the Recyclables]: RFID and the Handling of Municipa...
ijseajournal5 visualizações
SUMIT SQL PROJECT SUPERSTORE 1.pptx por Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 11 visualizações
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L... por Anowar Hossain
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
Anowar Hossain12 visualizações
Advances in micro milling: From tool fabrication to process outcomes por Shivendra Nandan
Advances in micro milling: From tool fabrication to process outcomesAdvances in micro milling: From tool fabrication to process outcomes
Advances in micro milling: From tool fabrication to process outcomes
Shivendra Nandan5 visualizações
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... por AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1263 visualizações
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) por Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Tsuyoshi Horigome23 visualizações
sam_software_eng_cv.pdf por sammyigbinovia
sam_software_eng_cv.pdfsam_software_eng_cv.pdf
sam_software_eng_cv.pdf
sammyigbinovia5 visualizações
Generative AI Models & Their Applications por SN
Generative AI Models & Their ApplicationsGenerative AI Models & Their Applications
Generative AI Models & Their Applications
SN6 visualizações
Saikat Chakraborty Java Oracle Certificate.pdf por SaikatChakraborty787148
Saikat Chakraborty Java Oracle Certificate.pdfSaikat Chakraborty Java Oracle Certificate.pdf
Saikat Chakraborty Java Oracle Certificate.pdf
SaikatChakraborty78714815 visualizações
An approach of ontology and knowledge base for railway maintenance por IJECEIAES
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenance
IJECEIAES12 visualizações

Spring boot

  • 1. Spring Boot Code with 0% Configuration Gyenendra Yadav Jindal InfoSolutions
  • 2. Introduction – pivotal Say…  Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.  You can use Spring Boot to create Java applications that can be started using java -jar or more traditional war deployments. We also provide a command line tool that runs “spring scripts”.
  • 4. WHY We Need Spring Boot?  Spring Boot is next generation attempt to easy spring setup.  Spring Boot’s main benefit is configuring the resources based on what it finds in the classpath.  If your Maven POM includes JPA dependencies and a MYSQL driver, then Spring Boot will setup a persistence unit based on MySQL. If you’ve added a web dependency, then you will get Spring MVC configured with defaults.  When we talk about defaults, Spring Boot has its own opinions. If you are not specifying the details, it will use its own default configurations. If you want persistence, but don’t specify anything else in your POM file, then Spring Boot configures Hibernate as a JPA provider with an HSQLDB database.
  • 5. primary goals  To provide a radically faster and widely accessible getting started development experience for all Spring development. Since spring community has evolved so big, it is time to re-invent the way how spring applications are deployed in much quicker turn around time.  To be get started so quickely using the default values which are supported out of the box in the Spring Boot configurations.  To provide bunch of non-functional features/solutions that are very much common to large scale projects (e.g. embedded servers, security, metrics, health checks, externalized configuration).
  • 6. What Spring Boot brings to the table ?  Convention over configuration  Standardization for Microservices  Integrated Server for Development  Cloud Support  Adapt & Support for 3rd Party Library
  • 8. Spring Boot Auto Configure  Module to auto configure a wide range of Spring projects.  It will detect availability of certain frameworks (Spring Batch, Spring Data JPA, Hibernate, JDBC).  When detected it will try to auto configure that framework with some sensible defaults, which in general can be overridden by configuration in an application.properties/yml(yaml-data serialization language) file.
  • 9. Spring Boot Core The base for other modules, but it also provides some functionality that can be used on its own, eg. using command line arguments and YAML files as Spring Environment property sources and automatically binding environment properties to Spring bean properties (with validation).
  • 10. Spring Boot CLI A command line interface, based on ruby, to start/stop spring boot created applications.
  • 11. Spring Boot Actuator  This project, when added, will enable certain enterprise features (Security, Metrics, Default Error pages) to your application.  As the auto configure module it uses auto detection to detect certain frameworks/features of your application. For an example, you can see all the REST Services defined in a web application using Actuator.
  • 12. Spring Boot Starters  Different quick start projects to include as a dependency in your maven or gradle build file.  It will have the needed dependencies for that type of application.  Currently there are many starter projects and many more are expected to be added.
  • 13. Spring Boot Tools  The Maven and Gradle build tool as well as the custom Spring Boot Loader (used in the single executable jar/war) is included in this project.
  • 14. How to use Spring Boot  You can use spring initialize to create the initial setup. You can visit either start.spring.io or use STS (Spring Tool Suite) Support available in IDEA or Eclipse to choose all the Spring Boot Starters  You need to also choose whether to use Maven or Gradle as the build tool.  If you are using start.spring.io, you need to then download the zip and configure your workspace. Otherwise using your preferred IDE will automatically create the required file in the workspace.  Add your code as required  You can either use mvn clean package or use IDEA or Eclipse to build and create the jar file.  By default the JAR would include integrated Tomcat server, so just by executing the JAR you should be able to use your program.
  • 19. Create Project  Goto Window Menu -> Perspective ->Spring  Goto File Menu ->New -> Spring Starter Project
  • 25. MyAppApplication Class package com.apps; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MyAppApplication { public static void main(String[] args) { SpringApplication.run(MyAppApplication.class, args); } }
  • 26. @SpringBootApplication annotation  @SpringBootApplication annotation  Many Spring Boot developers always have their main class annotated with @Configuration, @EnableAutoConfiguration and @ComponentScan. Since these annotations are so frequently used together (especially if you follow the best practices above), Spring Boot provides a convenient @SpringBootApplication alternative.  The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes:
  • 27. SpringApplication.run()  You need to run Application.run() because this method starts whole Spring Framework. Code below integrates your main() with Spring Boot.  public class SpringApplication extends Object  Classes that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:  Create an appropriate ApplicationContext instance (depending on your classpath)  Register a CommandLinePropertySource to expose command line arguments as Spring properties  Refresh the application context, loading all singleton beans  Trigger any CommandLineRunner beans  In most circumstances the static run(Object, String[]) method can be called directly from your main method to bootstrap your application:
  • 28. application.properties File  spring.datasource.url=jdbc:mysql://localhost:3306/springboot  spring.datasource.username=admin  spring.datasource.password=admin  spring.datasource.driver-class-name=com.mysql.jdbc.Driver  # Allows Hibernate to generate SQL optimized for a particular DBMS  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Di alect  # Number of ms to wait before throwing an exception if no connection is available.  spring.datasource.tomcat.max-wait=10000  # Maximum no of active conn that can be allocated from this pool at the same time.  spring.datasource.tomcat.max-active=50  # Validate the connection before borrowing it from the pool.  spring.datasource.tomcat.test-on-borrow=true
  • 29. Continue…….  # Keep the connection alive if idle for a long time (needed in production)  spring.datasource.dbcp.test-while-idle=true  spring.datasource.dbcp.validation-query=SELECT 1  # Naming strategy  spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy  # Hibernate ddl auto (create, create-drop, update): with "update" the database  # schema will be automatically updated accordingly to java entities found in  # the project  spring.jpa.hibernate.ddl-auto=update  # Show or not log for each sql query  spring.jpa.show-sql = true
  • 30. Load Custom Application Context package com.apps; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @ImportResource("applicationContext.xml") public class MyAppApplication { public static void main(String[] args) { SpringApplication.run(MyAppApplication.class, args); } }
  • 32. Thank you  References  http://docs.spring.io/spring-boot/docs/2.0.x-SNAPSHOT/reference/html/  http://www.adeveloperdiary.com/java/spring-boot/an-introduction-to-spring- boot/  Assignment For you  Configure yourself  How to create jar for deployment on production server