SlideShare una empresa de Scribd logo
1 de 32
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”.
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.
Environment Setup for Eclipse
Create Project
 Goto Window Menu -> Perspective ->Spring
 Goto File Menu ->New -> Spring Starter Project
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);
}
}
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 

Similar a Spring boot

Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsmichaelaaron25322
 
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
 
Building a Spring Boot Application - Ask the Audience!
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 🎸
 
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 testHyukSun Kwon
 
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)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)🎤 Hanno Embregts 🎸
 
Spring Boot Whirlwind Tour
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind TourVMware Tanzu
 
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptx
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptxdokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptx
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptxAppster1
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Gunith Devasurendra
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
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
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfAppster1
 
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)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)🎤 Hanno Embregts 🎸
 
Springboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-exampleSpringboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-exampleHyukSun Kwon
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSUFYAN SATTAR
 
Spring boot vs spring framework razor sharp web applications
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 applicationsKaty Slemon
 
Spring boot.pptx
Spring boot.pptxSpring boot.pptx
Spring boot.pptxKartikSang2
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservicesNilanjan Roy
 

Similar a Spring boot (20)

Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
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
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
 
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
 
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)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
 
Spring Boot Whirlwind Tour
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
 
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptx
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptxdokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptx
dokumen.tips_introduction-to-spring-boot-58bb649a21ce5.pptx
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
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
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
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)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
 
Spring boot
Spring bootSpring boot
Spring boot
 
Springboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-exampleSpringboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-example
 
Spring competitive tests
Spring competitive testsSpring competitive tests
Spring competitive tests
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Spring boot vs spring framework razor sharp web applications
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
 
Spring boot.pptx
Spring boot.pptxSpring boot.pptx
Spring boot.pptx
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
 

Último

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...Health
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stageAbc194748
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 

Último (20)

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 

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”.
  • 3.
  • 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.
  • 15.
  • 17.
  • 18.
  • 19. Create Project  Goto Window Menu -> Perspective ->Spring  Goto File Menu ->New -> Spring Starter Project
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 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); } }
  • 31.
  • 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