SlideShare a Scribd company logo
Introduction to Spring Boot
Trey Howard
@thoward333
thoward333
https://www.linkedin.com/in/treyhoward
Why Spring?
● Dependency Injection
○ Promotes more maintainable code
○ Promotes testable code
● First class support for all layers of the stack
○ Tomcat, Jetty, Undertow
○ View: JSP, Velocity, Freemarker, JSON, REST/SOAP
○ Repository: Hibernate, JPA, JDBC
○ Database: RDBMS and NoSQL
○ Testing: JUnit, Mockito, Spring Test
Why Spring Boot?
● More choices = More complexity
● Inconsistent dependency versions
● @Autoconfiguration
● Maven or Gradle
● Convention over Configuration
○ application.properties (and -profile.properties)
○ src/main/resources: /templates, /static
● Harmonizes library versions (Spring and non-Spring)
○ Version of Spring Boot is the only thing you have to manage
● Opinionated
○ Embedded Tomcat for MVC app, 1-line config change to Jetty, Undertow or none
○ Detects Spring Security on classpath and wires up sensible defaults
■ You don’t want Spring Security? 1-line change to turn off
■ Don’t like the OOTB settings? Extend this class
● spring-boot-starter-actuator
Benefits of Spring Boot
Creating a Spring Boot Project
● Create a seed project using web, IDE, or CLI
○ http://start.spring.io/
○ Download Spring Source STS (Latest 3.8.1)
○ Install CLI (Latest 1.4.0)
■ Creates, runs & more
● Secret sauce: Parent pom.xml
● Include spring-boot-starter-* modules
Spring Boot CLI
Entire project is single file: hello.groovy
@RestController
class WebApplication {
@RequestMapping("/")
String home() {
"Hello World!"
}
}
spring run hello.groovy
Live Demo - Create New Boot Project
http://start.spring.io/
Demo - REST API
● Basic REST API
● Hard-coded repository class for now
Demo - JDBC
● spring-boot-starter-jdbc
● Uses JdbcTemplate to query database
Demo - JPA
● spring-boot-starter-data-jpa
● Uses CrudRepository to query database
● Notice it’s an interface, not a class
● Method names drive fields that are queried
○ findByEmail(String email) will query db with ‘...where email = ?’
Demo - JPA Data REST
● spring-boot-starter-data-jpa & spring-boot-starter-data-rest
● No @Controller
● Because we have included spring-boot-starter-data-rest, Spring creates
REST endpoints for all @Entity classes
Spring Security with Spring Boot
● spring-boot-starter-security
● Add @EnableWebSecurity
OAuth2 with Spring Boot
● Add @EnableAuthorizationServer
○ Creates /oath/token endpoint that creates OAuth tokens
● Add @EnableResourceServer
○ Receives OAuth token via HTTP Header
● Demo
○ curl localhost:8080/oauth/token -d scope=read -d grant_type=password -d
username=springboot -d password=workshop -u myid:mysecret
○ curl localhost:8080 -H “Authorization: Bearer <access_token>”
Goodies in Spring Web (Boot 1.4.0)
● spring-devtools: Dual Classpath and Live Reload
● URL Binding annotations:
○ @GetMapping, @PostMapping, etc (@RequestMapping pre-1.4.0)
○ @RestControllerAdvice (@ControllerAdvice + @ResponseBody pre-1.4.0)
○ @SpringBootTest, @WebMvcTest, @AutoConfigureMockMvc, @MockBean, @SpyBean
● HTTP Options, Head are now supported
● RestTemplate setDefaultUriVariables
● @ConfigurationProperties / @EnableConfigurationProperties
○ Strongly typed properties backed by property files
○ Optional metadata for IDE, extra devtools module will auto-generate metadata
Goodies in Spring Security (Boot 1.4.0)
● Can access Principal in SpEL expression in Repository layer @Query:
@Query(“select * from foo where owner = ?#{principal.userId}”)
public Foo getFooForCurrentUser() ...
● mvcMatcher - alternative to antMatcher, has suffix vulnerability /foo vs /foo/
● @EnableAuthorizationServer / @EnableResourceServer
Resources
● Spring Boot Reference Guide:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
○ Installing Spring Boot CLI:
http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-installing-spring-bo
ot.html#getting-started-installing-the-cli
● Initializr: http://start.spring.io/
● What’s new in Spring Boot 1.4:
https://spring.io/blog/2016/07/28/spring-boot-1-4-released
Introduction to Spring Boot

More Related Content

PDF
Spring boot introduction
PPTX
Spring Boot Tutorial
ODP
Xke spring boot
PPTX
Spring boot
PDF
Spring Framework - Core
PPTX
Spring boot Introduction
PPT
Spring Boot in Action
PPTX
Spring data jpa
Spring boot introduction
Spring Boot Tutorial
Xke spring boot
Spring boot
Spring Framework - Core
Spring boot Introduction
Spring Boot in Action
Spring data jpa

What's hot (20)

PDF
Spring Boot
PPT
Spring Core
PDF
Spring Boot
PDF
Spring annotation
PPT
Java Persistence API (JPA) Step By Step
PPTX
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
PDF
REST APIs with Spring
PPTX
Spring jdbc
PDF
Spring Boot
PDF
React js
PDF
Tomcat and apache httpd training
PPTX
Spring Boot and REST API
PPTX
Reactjs
PPTX
Introduction to Spring Framework
PDF
Java persistence api 2.1
PPTX
Spring boot
PPTX
Spring boot - an introduction
PDF
Spring Boot & Actuators
PDF
Spring Data JPA
PPTX
Spring Boot
Spring Boot
Spring Core
Spring Boot
Spring annotation
Java Persistence API (JPA) Step By Step
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
REST APIs with Spring
Spring jdbc
Spring Boot
React js
Tomcat and apache httpd training
Spring Boot and REST API
Reactjs
Introduction to Spring Framework
Java persistence api 2.1
Spring boot
Spring boot - an introduction
Spring Boot & Actuators
Spring Data JPA
Spring Boot
Ad

Viewers also liked (16)

PDF
Spring Boot quickstart
ODP
Depression und Social Media
PDF
Java™ in Web 2.0
PDF
Microservices with spring boot
PDF
Modern Java web applications with Spring Boot and Thymeleaf
PDF
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
PPTX
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
PDF
Spring Boot
PDF
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
PDF
DevOpsDays Baltimore March 2017 - Continuous Integration: A bittersweet love ...
PDF
Spring Framework ふりかえりと4.3新機能
PPTX
jDays - Spring Boot under the Hood
PDF
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
PDF
Microservices - java ee vs spring boot and spring cloud
PDF
Spring Boot Microservices vs Akka Actor Cluster
PDF
Lineにおけるspring frameworkの活用
Spring Boot quickstart
Depression und Social Media
Java™ in Web 2.0
Microservices with spring boot
Modern Java web applications with Spring Boot and Thymeleaf
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
Spring Boot
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
DevOpsDays Baltimore March 2017 - Continuous Integration: A bittersweet love ...
Spring Framework ふりかえりと4.3新機能
jDays - Spring Boot under the Hood
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
Microservices - java ee vs spring boot and spring cloud
Spring Boot Microservices vs Akka Actor Cluster
Lineにおけるspring frameworkの活用
Ad

Similar to Introduction to Spring Boot (20)

PDF
Load testing in Zonky with Gatling
PPTX
Testing Django APIs
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
PDF
Presto conferencetokyo2019
PDF
Rediscovering Spring with Spring Boot(1)
PDF
Find the bottleneck of your system
PDF
Core Java Programming Language (JSE) : Chapter XIII - JDBC
PPTX
Journey through high performance django application
PDF
High Availability PostgreSQL with Zalando Patroni
PDF
EuroPython 2013 - Python3 TurboGears Training
PPTX
An introduction to Node.js application development
PDF
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
PDF
Socket programming, and openresty
PDF
POUG2019 - Test your PL/SQL - your database will love you
PDF
DevOops & How I hacked you DevopsDays DC June 2015
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
Spring Boot 3 And Beyond
PDF
Microservices with Micronaut
PPTX
Distributed tracing 101
Load testing in Zonky with Gatling
Testing Django APIs
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Presto conferencetokyo2019
Rediscovering Spring with Spring Boot(1)
Find the bottleneck of your system
Core Java Programming Language (JSE) : Chapter XIII - JDBC
Journey through high performance django application
High Availability PostgreSQL with Zalando Patroni
EuroPython 2013 - Python3 TurboGears Training
An introduction to Node.js application development
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Socket programming, and openresty
POUG2019 - Test your PL/SQL - your database will love you
DevOops & How I hacked you DevopsDays DC June 2015
Python RESTful webservices with Python: Flask and Django solutions
Spring Boot 3 And Beyond
Microservices with Micronaut
Distributed tracing 101

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Tartificialntelligence_presentation.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Univ-Connecticut-ChatGPT-Presentaion.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Assigned Numbers - 2025 - Bluetooth® Document
Tartificialntelligence_presentation.pptx
Encapsulation theory and applications.pdf
1. Introduction to Computer Programming.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative study of natural language inference in Swahili using monolingua...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Introduction to Spring Boot

  • 1. Introduction to Spring Boot Trey Howard @thoward333 thoward333 https://www.linkedin.com/in/treyhoward
  • 2. Why Spring? ● Dependency Injection ○ Promotes more maintainable code ○ Promotes testable code ● First class support for all layers of the stack ○ Tomcat, Jetty, Undertow ○ View: JSP, Velocity, Freemarker, JSON, REST/SOAP ○ Repository: Hibernate, JPA, JDBC ○ Database: RDBMS and NoSQL ○ Testing: JUnit, Mockito, Spring Test
  • 3. Why Spring Boot? ● More choices = More complexity ● Inconsistent dependency versions ● @Autoconfiguration
  • 4. ● Maven or Gradle ● Convention over Configuration ○ application.properties (and -profile.properties) ○ src/main/resources: /templates, /static ● Harmonizes library versions (Spring and non-Spring) ○ Version of Spring Boot is the only thing you have to manage ● Opinionated ○ Embedded Tomcat for MVC app, 1-line config change to Jetty, Undertow or none ○ Detects Spring Security on classpath and wires up sensible defaults ■ You don’t want Spring Security? 1-line change to turn off ■ Don’t like the OOTB settings? Extend this class ● spring-boot-starter-actuator Benefits of Spring Boot
  • 5. Creating a Spring Boot Project ● Create a seed project using web, IDE, or CLI ○ http://start.spring.io/ ○ Download Spring Source STS (Latest 3.8.1) ○ Install CLI (Latest 1.4.0) ■ Creates, runs & more ● Secret sauce: Parent pom.xml ● Include spring-boot-starter-* modules
  • 6. Spring Boot CLI Entire project is single file: hello.groovy @RestController class WebApplication { @RequestMapping("/") String home() { "Hello World!" } } spring run hello.groovy
  • 7. Live Demo - Create New Boot Project http://start.spring.io/
  • 8. Demo - REST API ● Basic REST API ● Hard-coded repository class for now
  • 9. Demo - JDBC ● spring-boot-starter-jdbc ● Uses JdbcTemplate to query database
  • 10. Demo - JPA ● spring-boot-starter-data-jpa ● Uses CrudRepository to query database ● Notice it’s an interface, not a class ● Method names drive fields that are queried ○ findByEmail(String email) will query db with ‘...where email = ?’
  • 11. Demo - JPA Data REST ● spring-boot-starter-data-jpa & spring-boot-starter-data-rest ● No @Controller ● Because we have included spring-boot-starter-data-rest, Spring creates REST endpoints for all @Entity classes
  • 12. Spring Security with Spring Boot ● spring-boot-starter-security ● Add @EnableWebSecurity
  • 13. OAuth2 with Spring Boot ● Add @EnableAuthorizationServer ○ Creates /oath/token endpoint that creates OAuth tokens ● Add @EnableResourceServer ○ Receives OAuth token via HTTP Header ● Demo ○ curl localhost:8080/oauth/token -d scope=read -d grant_type=password -d username=springboot -d password=workshop -u myid:mysecret ○ curl localhost:8080 -H “Authorization: Bearer <access_token>”
  • 14. Goodies in Spring Web (Boot 1.4.0) ● spring-devtools: Dual Classpath and Live Reload ● URL Binding annotations: ○ @GetMapping, @PostMapping, etc (@RequestMapping pre-1.4.0) ○ @RestControllerAdvice (@ControllerAdvice + @ResponseBody pre-1.4.0) ○ @SpringBootTest, @WebMvcTest, @AutoConfigureMockMvc, @MockBean, @SpyBean ● HTTP Options, Head are now supported ● RestTemplate setDefaultUriVariables ● @ConfigurationProperties / @EnableConfigurationProperties ○ Strongly typed properties backed by property files ○ Optional metadata for IDE, extra devtools module will auto-generate metadata
  • 15. Goodies in Spring Security (Boot 1.4.0) ● Can access Principal in SpEL expression in Repository layer @Query: @Query(“select * from foo where owner = ?#{principal.userId}”) public Foo getFooForCurrentUser() ... ● mvcMatcher - alternative to antMatcher, has suffix vulnerability /foo vs /foo/ ● @EnableAuthorizationServer / @EnableResourceServer
  • 16. Resources ● Spring Boot Reference Guide: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/ ○ Installing Spring Boot CLI: http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-installing-spring-bo ot.html#getting-started-installing-the-cli ● Initializr: http://start.spring.io/ ● What’s new in Spring Boot 1.4: https://spring.io/blog/2016/07/28/spring-boot-1-4-released