Rasheed Amir presents on Spring Boot. He discusses how Spring Boot aims to help developers build production-grade Spring applications quickly with minimal configuration. It provides default functionality for tasks like embedding servers and externalizing configuration. Spring Boot favors convention over configuration and aims to get developers started quickly with a single focus. It also exposes auto-configuration for common Spring and related technologies so that applications can take advantage of them without needing to explicitly configure them.
2. 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
6. 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!
7. 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
9. 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.
11. 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
12. 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!"
}
}
13. 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!"
}
}
14. 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!"
}
}
15. 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);
// }
}
17. 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....
28. 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
29. 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
31. 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)
35. 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