SlideShare a Scribd company logo
1 of 36
Download to read offline
www.aurorasolutions.iowww.aurorasolutions.io
Spring Boot Introduction
Presenter: Rasheed Amir
www.aurorasolutions.iowww.aurorasolutions.io
Who is Rasheed?
❏ Programmer (Java, Groovy, C#, JavaScript). Architect. Agile Coach.
❏ Co-founder Aurora Solutions, FixTelligent
❏ Serial Entrepreneur
❏ Certified Instructor for Spring Courses (Core, Web & Integration)
❏ You can find me on LinkedIn
www.aurorasolutions.iowww.aurorasolutions.io
Overview
www.aurorasolutions.iowww.aurorasolutions.io
www.aurorasolutions.iowww.aurorasolutions.io
www.aurorasolutions.iowww.aurorasolutions.io
Spring Boot Goals
➔ Introduce developers to Spring Boot, an opinionated way to rapidly build production
grade Spring applications quickly and with minimal fuss.
➔ Be opinionated out of the box, but get out of the way quickly as requirements start to
diverge from the defaults
➔ Provide a range of non-functional features that are common to large classes of projects (e.
g. embedded servers, security, metrics, health checks, externalized configuration)
➔ Absolutely no code generation and no requirement for XML configuration!
www.aurorasolutions.iowww.aurorasolutions.io
Spring Boot Goals...
➔ Single point of focus (as opposed to large collection of spring-* projects)
➔ A tool for getting started very quickly with Spring
➔ Common non-functional requirements for a "real" application
➔ Exposes a lot of useful features by default
➔ Gets out of the way quickly if you want to change defaults
www.aurorasolutions.iowww.aurorasolutions.io
Installation
Spring Boot CLI
www.aurorasolutions.iowww.aurorasolutions.io
Installation - Spring CLI
Spring CLI Installer -- Installer for the spring CLI command on Un*x-like system (should work
on Linux, Mac or Cygwin).
You can curl http://start.spring.io/install.sh | sh, or download the script and run it.
www.aurorasolutions.iowww.aurorasolutions.io
Getting Started Quickly!
in Groovy!
www.aurorasolutions.iowww.aurorasolutions.io
Getting Started Quickly in Groovy!
Here’s a really simple web application that you can use to test your installation. Create a file
called Welcome.groovy:
@RestController
class WelcomeToSpringBootMeetup {
@RequestMapping("/")
String home() {
"Welcome Everyone!"
}
}
$ spring run --watch Welcome.groovy
... application is running at http://localhost:8080
www.aurorasolutions.iowww.aurorasolutions.io
How did it work?
// import org.springframework.web.bind.annotation.RestController
// other imports …
@RestController
class WelcomeToSpringBootMeetup {
@RequestMapping("/")
String home() {
"Welcome Everyone!"
}
}
www.aurorasolutions.iowww.aurorasolutions.io
How did it work?
// import org.springframework.web.bind.annotation.RestController
// other imports …
// @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0")
@RestController
class WelcomeToSpringBootMeetup {
@RequestMapping("/")
String home() {
"Welcome Everyone!"
}
}
www.aurorasolutions.iowww.aurorasolutions.io
How did it work?
// import org.springframework.web.bind.annotation.RestController
// other imports …
// @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0")
// @EnableAutoConfiguration
@RestController
class WelcomeToSpringBootMeetup {
@RequestMapping("/")
String home() {
"Welcome Everyone!"
}
}
www.aurorasolutions.iowww.aurorasolutions.io
How did it work?
// import org.springframework.web.bind.annotation.RestController
// other imports …
// @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0")
// @EnableAutoConfiguration
@RestController
class WelcomeToSpringBootMeetup {
@RequestMapping("/")
String home() {
"Welcome Everyone!"
}
// public static void main(String[] args) {
// SpringApplication.run(Example.class, args);
// }
}
www.aurorasolutions.iowww.aurorasolutions.io
Getting Started Quickly!
in Java!
www.aurorasolutions.iowww.aurorasolutions.io
Getting Started Quickly in Java!
Step 1: Create a folder; name it “helloworld”. Create an empty file called “pom.xml”. Copy the
content given below...
Step 2: Run mvn package
Step 3: Run mvn dependency:tree
Step 4: Add spring-boot-starter-web dependency in pom
Step 5: Run mvn dependency:tree
Step 6: Create directory structure (src/main/java/com/helloworld) and file named “HelloWorld.
java”. Copy the code give below...
Step 7: Running the HelloWorld: mvn spring-boot:run
Step 8: Open the browser: If you open a web browser to http://localhost:8080 and you will see
something…
Step 9: Create executable jar....
www.aurorasolutions.iowww.aurorasolutions.io
Starter POM’s
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
➔ Standard Maven POMs
➔ Define dependencies that we recommend
➔ Parent optional
➔ Available for web, batch, integration, data, amqp, aop, jdbc, ...
➔ e.g. data = hibernate + spring-data + JSR 303
www.aurorasolutions.iowww.aurorasolutions.io
SpringApplication
SpringApplication app = new SpringApplication(MyApplication.class);
app.setShowBanner(false);
app.run(args);
➔ Gets a running Spring ApplicationContext
➔ Uses EmbeddedWebApplicationContext for web apps
➔ Can be a single line: SpringApplication.run(MyApplication.class, args)
www.aurorasolutions.iowww.aurorasolutions.io
SpringApplication
@Configuration
@EnableAutoConfiguration
public class Welcome {
}
➔ Attempts to auto-configure your application
➔ Backs off as you define your own beans
➔ Regular @Configuration classes
➔ Usually with @ConditionalOnClass and @ConditionalOnMissingBean
www.aurorasolutions.iowww.aurorasolutions.io
Production Packaging
Maven plugin (using spring-boot-starter-parent):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
$ mvn package or mvn clean install
$ java -jar <file-name>.jar
www.aurorasolutions.iowww.aurorasolutions.io
Production Packaging
$ java -jar <file-name.jar>
➔ Easy to understand structure
➔ No unpacking or start scripts required
➔ Typical REST app ~10Mb
www.aurorasolutions.iowww.aurorasolutions.io
Command Line Arguments
@Value("${name}")
private String name;
SpringApplication adds command line arguments to the Spring Environment so you can refer
inject them into beans:
$ java -jar <file-name>.jar --name=Rasheed
You can also configure many aspects of Spring Boot itself:
$ java -jar <file-name>.jar --server.port=9999
www.aurorasolutions.iowww.aurorasolutions.io
Externalizing Configuration to Properties
server.port: 9000
Just put application.properties in your classpath or next to you jar, e.g.
application.properties
Properties can be overridden (command line arg > file > classpath)
www.aurorasolutions.iowww.aurorasolutions.io
Using YAML
server:
port: 9000
Just include snake-yaml.jar and put application.yml in your classpath e.g.
application.yml
Both properties and YAML add entries with period-separated paths to the Spring Environment.
www.aurorasolutions.iowww.aurorasolutions.io
Binding Configuration To Beans
@ConfigurationProperties(prefix="mine")
public class MyPoperties {
private Resource location;
private boolean skip = true;
// ... getters and setters
}
MyProperties.java
application.properties
mine.location: classpath:mine.xml
mine.skip: false
Explore ServerProperties.java
www.aurorasolutions.iowww.aurorasolutions.io
Customizing Configuration Location
Set
➔ spring.config.name - default application, can be comma-separated list
➔ spring.config.location - a Resource path, overrides name
$ java -jar <file-name>.jar --spring.config.name=production
www.aurorasolutions.iowww.aurorasolutions.io
Spring Profiles
Activate external configuration with a Spring profile file name convention e.g. application-development.
properties
or nested documents in YAML:
defaults: etc…
---
spring:
profiles: development, qa
other:
stuff: more stuff...
application.yml
Set the default spring profile in external configuration, e.g: application.properties
spring.profiles.active: default, qa
www.aurorasolutions.iowww.aurorasolutions.io
Logging
➔ Spring Boot provides default configuration files for 3 common logging frameworks:
logback, log4j and java.util.logging
➔ Starters (and Samples) use logback with colour output
➔ External configuration and classpath influence runtime behavior
➔ LoggingApplicationContextInitializer sets it all up
www.aurorasolutions.iowww.aurorasolutions.io
Autoconfigured Behavior
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
Let’s extend the demo and see what we can get by just modifying the classpath, e.g.
● Add an in memory database
www.aurorasolutions.iowww.aurorasolutions.io
Available Autoconfigured Behaviour...
● Embedded servlet container (Tomcat or Jetty)
● JDBC: DataSource and JdbcTemplate
● JPA, JMS, AMQP (Rabbit), AOP
● Websocket
● Spring Data JPA (scan for repositories) and Mongodb
● Thymeleaf
● Mobile
● Batch processing
● Reactor for events and async processing
● Actuator features (Security, Audit, Metrics, Trace)
www.aurorasolutions.iowww.aurorasolutions.io
The Actuator
Monitoring Endpoints
www.aurorasolutions.iowww.aurorasolutions.io
The Actuator
Adds common non-functional features to your application and exposes MVC endpoints to
interact with them.
Provides following endpoints: /metrics, /health, /trace, /dump, /shutdown, /beans, /env, /info
www.aurorasolutions.iowww.aurorasolutions.io
Spring Boot Modules
www.aurorasolutions.iowww.aurorasolutions.io
● Spring Boot - main library supporting the other parts of Spring Boot
● Spring Boot Autoconfigure - single @EnableAutoConfiguration annotation creates a
whole Spring context
● Spring Boot Starters - a set of convenient dependency descriptors that you can include in
your application.
● Spring Boot CLI - compiles and runs Groovy source as a Spring application
● Spring Boot Actuator - common non-functional features that make an app instantly
deployable and supportable in production
● Spring Boot Tools - for building and executing self-contained JAR and WAR archives
● Spring Boot Samples - a wide range of sample apps
www.aurorasolutions.iowww.aurorasolutions.io
Build WAR file!

More Related Content

What's hot

Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 

What's hot (20)

Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 

Similar to Spring boot introduction

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
 
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 🎸
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 

Similar to Spring boot introduction (20)

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
 
Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022
 
Os Haase
Os HaaseOs Haase
Os Haase
 
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)
 
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
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
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!
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
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)
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Scala, Functional Programming and Team Productivity
Scala, Functional Programming and Team ProductivityScala, Functional Programming and Team Productivity
Scala, Functional Programming and Team Productivity
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third Plugin
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
 
Play framework
Play frameworkPlay framework
Play framework
 
React django
React djangoReact django
React django
 
GlassFish Embedded API
GlassFish Embedded APIGlassFish Embedded API
GlassFish Embedded API
 

More from Rasheed Waraich

Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web Apps
Rasheed Waraich
 

More from Rasheed Waraich (6)

REST API Best (Recommended) Practices
REST API Best (Recommended) PracticesREST API Best (Recommended) Practices
REST API Best (Recommended) Practices
 
Java 8 date & time api
Java 8 date & time apiJava 8 date & time api
Java 8 date & time api
 
Ship python apps with docker!
Ship python apps with docker!Ship python apps with docker!
Ship python apps with docker!
 
Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web Apps
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
Angular js recommended practices - mini
Angular js   recommended practices - miniAngular js   recommended practices - mini
Angular js recommended practices - mini
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Spring boot introduction