SlideShare a Scribd company logo
1 of 19
Download to read offline
Spring Boot
- By Vinay Prajapati
Agenda
• What and Why?
• Key features of Spring boot.
• Prototyping using CLI.
• Working with gradle.
• Managing profiles aka environment just like in grails
• Binding Properties
• Packaging Executable Jars / Fat jars
• Miscellaneous
What & Why?
• Spring-boot provides a quick way to create a Spring based
application from dependency management to convention over
configuration.
• Not a replacement for Spring framework but it presents a small
surface area for users to approach and extract value from the
rest of Spring.
• Helps you get up and running ASAP.
• Grails 3.0 is based on Spring Boot.
3
image source : http://spring.io/blog/2013/08/06/spring-boot-simplifying-spring-for-everyone
Key Features
• Stand-alone Spring applications with negligible efforts.
• No code generation and no requirement for XML Config
• Automatic configuration by creating sensible defaults
• Provides Starter dependencies / Starter POMs
• Structure your code as you like
• Supports Gradle and Maven
• Provides common non-functional production ready features for a
“Real” application such as
– security
– metrics
– health checks
– externalised configuration
Rapid Prototyping : Spring CLI
• Quickest way to get a spring app off the ground
• Allows you to run groovy scripts without much boilerplate code
• Not recommended for production
Getting Started Quickly using CLI
@Controller
class Example {
@RequestMapping("/")
@ResponseBody
public String helloWorld() {
"Hello Spring boot audience!!!"
}
}
What Just happened?
// import org.springframework.web.bind.annotation.Controller
// other imports ...
// @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0")
// @EnableAutoConfiguration
@Controller
class Example {
@RequestMapping("/")
@ResponseBody
public String hello() {
return "Hello World!";
}
// public static void main(String[] args) {
// SpringApplication.run(Example.class, args);
// }
}
Starter POMs
• One-stop-shop for all the Spring and related technology
• A set of convenient dependency descriptors
• Contain a lot of the dependencies that you need to get a project up and
running quickly
• All starters follow a similar naming pattern;
– spring-boot-starter-*
• Examples
– spring-boot-starter-web(tomcat and spring mvc dependencies)
– spring-boot-starter-actuator
– spring-boot-starter-security
– spring-boot-starter-data-rest
– spring-boot-starter-amqp
– spring-boot-starter-data-jpa
– spring-boot-starter-data-elasticsearch
– spring-boot-starter-data-mongodb
–
Demo : Starter POMs
@Grab('spring-boot-starter-security')
@Grab('spring-boot-starter-actuator')
@Grab('spring-boot-starter-jetty')
@Controller
class Example {
@RequestMapping("/")
@ResponseBody
public String helloWorld() {
return "Hello Audience!!!"
}
}
//security.user.name
//security.user.password
//actuator endpoints: /beans, /health, /mappings, /metrics etc.
Lets go beyond prototyping : Gradle
Image source : http://www.drdobbs.com/jvm/why-build-your-java-projects-with-gradle/240168608
Gradle: for Spring boot app
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
buildscript {
repositories { mavenCentral()}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE")
classpath 'org.springframework:springloaded:1.2.0.RELEASE'
}
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
repositories { mavenCentral() }
dependencies {
compile 'org.codehaus.groovy:groovy-all'
compile 'org.springframework.boot:spring-boot-starter-web'
}
Environments and Profiles
• Put application.properties/application.yml somewhere in classpath
• Easy one: src/main/resources folder
12
app:
name: Springboot+Config+Yml+Demo
version: 1.0.0
server:
port: 8080
---
spring:
profiles: development
server:
port: 9001
application.yml
app.name=Springboot+Config+Demo
app.version=1.0.0
server.port=8080
application.properties
app.name=Springboot+Config+Demo
app.version=1.0.0
server.port=8080
application-development.properties
Examples
13
export SPRING_PROFILES_ACTIVE=development
export SERVER_PORT=8090
gradle bootRun
java -jar build/libs/demo-1.0.0.jar
java -jar -Dspring.profiles.active=development build/libs/dem-1.0.0.jar
java -jar -Dserver.port=8090 build/libs/demo-1.0.0.jar
OS env variable
with a -D argument (remember to put it before the main class or jar archive)
Binding properties
14
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
@Component
@ConfigurationProperties(prefix = "app")
class AppInfo {
String name
String version
}
Using ConfigurationProperties annotation
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
@Component
class AppConfig {
@Value('${app.name}')
String appName
@Value('${server.port}')
Integer port
}
Using Value annotation
Packaging executable jar and war files
15
$ gradle build
$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar
//...
apply plugin: 'war'
war {
baseName = 'myapp'
version = '0.5.0'
}
//....
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
// ...
}
$ gradle war
Packaging as jar with embedded tomcat
Packaging as war : configure build.groovy
Miscellaneous
- Enabling Disabling the Banner
- Changing the Banner
- Adding event Listeners
- Logging startup info
Takeaways
● Idea behind Spring Boot.
● It’s Core Features.
● Easy start with Spring Boot using CLI.
● Starter POMs.
● Using Spring boot with one of the build tools - gradle.
● Packaging executable jar files / war files.
● Some Misc.
References
19
https://github.com/bhagwat/spring-boot-samples
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-
started-gvm-cli-installation
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-cli/samples
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-
boot-starter-poms
start.spring.io
http://spring.io/guides/gs/accessing-mongodb-data-rest/
https://spring.io/guides/gs/accessing-data-mongodb/
https://spring.io/guides/gs/accessing-data-jpa/
http://www.gradle.org/
http://www.slideshare.net/Soddino/developing-an-application-with-spring-boot-34661781
http://presos.dsyer.com/decks/spring-boot-intro.html
http://pygments.org/

More Related Content

What's hot

Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupAccenture Hungary
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3VMware Tanzu
 
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...VMware Tanzu
 
Grails 3.0 Preview
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Previewgraemerocher
 
If Hemingway Wrote JavaDocs
If Hemingway Wrote JavaDocsIf Hemingway Wrote JavaDocs
If Hemingway Wrote JavaDocsVMware Tanzu
 
Resilient and Adaptable Systems with Cloud Native APIs
Resilient and Adaptable Systems with Cloud Native APIsResilient and Adaptable Systems with Cloud Native APIs
Resilient and Adaptable Systems with Cloud Native APIsVMware Tanzu
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...VMware Tanzu
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"IT Event
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with javaDPC Consulting Ltd
 
Spring Boot—Production Boost
Spring Boot—Production BoostSpring Boot—Production Boost
Spring Boot—Production BoostVMware Tanzu
 
Spring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewSpring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewVMware Tanzu
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tToshiaki Maki
 
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsGame of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsVMware Tanzu
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudMatt Stine
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Matt Raible
 
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...Daniel Bryant
 
Apache Continuum Build, Test, and Release
Apache Continuum Build, Test, and ReleaseApache Continuum Build, Test, and Release
Apache Continuum Build, Test, and Releaseelliando dias
 

What's hot (20)

Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology Meetup
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3
 
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
 
Grails 3.0 Preview
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Preview
 
If Hemingway Wrote JavaDocs
If Hemingway Wrote JavaDocsIf Hemingway Wrote JavaDocs
If Hemingway Wrote JavaDocs
 
Resilient and Adaptable Systems with Cloud Native APIs
Resilient and Adaptable Systems with Cloud Native APIsResilient and Adaptable Systems with Cloud Native APIs
Resilient and Adaptable Systems with Cloud Native APIs
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
Spring Boot—Production Boost
Spring Boot—Production BoostSpring Boot—Production Boost
Spring Boot—Production Boost
 
Spring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewSpring Cloud Data Flow Overview
Spring Cloud Data Flow Overview
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
 
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging PlatformsGame of Streams: How to Tame and Get the Most from Your Messaging Platforms
Game of Streams: How to Tame and Get the Most from Your Messaging Platforms
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring Cloud
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
 
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
 
Apache Continuum Build, Test, and Release
Apache Continuum Build, Test, and ReleaseApache Continuum Build, Test, and Release
Apache Continuum Build, Test, and Release
 

Similar to Spring boot wednesday

Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservicesNilanjan Roy
 
Bootify your spring application
Bootify your spring applicationBootify your spring application
Bootify your spring applicationJimmy Lu
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
 
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 🎸
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your developmentStrannik_2013
 
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 🎸
 
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 🎸
 
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
 
Springboot - A milestone framework in Java Development
Springboot - A milestone framework in Java DevelopmentSpringboot - A milestone framework in Java Development
Springboot - A milestone framework in Java DevelopmentExpeed Software
 
Java and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbJava and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbStaples
 
Java and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbJava and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbStaples
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact versionscalaconfjp
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
Enabling .NET Apps with Monitoring and Management Using Steeltoe
Enabling .NET Apps with Monitoring and Management Using SteeltoeEnabling .NET Apps with Monitoring and Management Using Steeltoe
Enabling .NET Apps with Monitoring and Management Using SteeltoeVMware Tanzu
 
Springboot and camel
Springboot and camelSpringboot and camel
Springboot and camelDeepak Kumar
 

Similar to Spring boot wednesday (20)

Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot for buidling microservices
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Bootify your spring application
Bootify your spring applicationBootify your spring application
Bootify your spring application
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails 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)
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
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!
 
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)
 
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
 
Springboot - A milestone framework in Java Development
Springboot - A milestone framework in Java DevelopmentSpringboot - A milestone framework in Java Development
Springboot - A milestone framework in Java Development
 
Java and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbJava and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo db
 
Java and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo dbJava and services code lab spring boot and spring data using mongo db
Java and services code lab spring boot and spring data using mongo db
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact version
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Enabling .NET Apps with Monitoring and Management Using Steeltoe
Enabling .NET Apps with Monitoring and Management Using SteeltoeEnabling .NET Apps with Monitoring and Management Using Steeltoe
Enabling .NET Apps with Monitoring and Management Using Steeltoe
 
Springboot and camel
Springboot and camelSpringboot and camel
Springboot and camel
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Spring boot wednesday

  • 1. Spring Boot - By Vinay Prajapati
  • 2. Agenda • What and Why? • Key features of Spring boot. • Prototyping using CLI. • Working with gradle. • Managing profiles aka environment just like in grails • Binding Properties • Packaging Executable Jars / Fat jars • Miscellaneous
  • 3. What & Why? • Spring-boot provides a quick way to create a Spring based application from dependency management to convention over configuration. • Not a replacement for Spring framework but it presents a small surface area for users to approach and extract value from the rest of Spring. • Helps you get up and running ASAP. • Grails 3.0 is based on Spring Boot. 3 image source : http://spring.io/blog/2013/08/06/spring-boot-simplifying-spring-for-everyone
  • 4. Key Features • Stand-alone Spring applications with negligible efforts. • No code generation and no requirement for XML Config • Automatic configuration by creating sensible defaults • Provides Starter dependencies / Starter POMs • Structure your code as you like • Supports Gradle and Maven • Provides common non-functional production ready features for a “Real” application such as – security – metrics – health checks – externalised configuration
  • 5. Rapid Prototyping : Spring CLI • Quickest way to get a spring app off the ground • Allows you to run groovy scripts without much boilerplate code • Not recommended for production
  • 6. Getting Started Quickly using CLI @Controller class Example { @RequestMapping("/") @ResponseBody public String helloWorld() { "Hello Spring boot audience!!!" } }
  • 7. What Just happened? // import org.springframework.web.bind.annotation.Controller // other imports ... // @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0") // @EnableAutoConfiguration @Controller class Example { @RequestMapping("/") @ResponseBody public String hello() { return "Hello World!"; } // public static void main(String[] args) { // SpringApplication.run(Example.class, args); // } }
  • 8. Starter POMs • One-stop-shop for all the Spring and related technology • A set of convenient dependency descriptors • Contain a lot of the dependencies that you need to get a project up and running quickly • All starters follow a similar naming pattern; – spring-boot-starter-* • Examples – spring-boot-starter-web(tomcat and spring mvc dependencies) – spring-boot-starter-actuator – spring-boot-starter-security – spring-boot-starter-data-rest – spring-boot-starter-amqp – spring-boot-starter-data-jpa – spring-boot-starter-data-elasticsearch – spring-boot-starter-data-mongodb –
  • 9. Demo : Starter POMs @Grab('spring-boot-starter-security') @Grab('spring-boot-starter-actuator') @Grab('spring-boot-starter-jetty') @Controller class Example { @RequestMapping("/") @ResponseBody public String helloWorld() { return "Hello Audience!!!" } } //security.user.name //security.user.password //actuator endpoints: /beans, /health, /mappings, /metrics etc.
  • 10. Lets go beyond prototyping : Gradle Image source : http://www.drdobbs.com/jvm/why-build-your-java-projects-with-gradle/240168608
  • 11. Gradle: for Spring boot app apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'spring-boot' buildscript { repositories { mavenCentral()} dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE") classpath 'org.springframework:springloaded:1.2.0.RELEASE' } } idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } repositories { mavenCentral() } dependencies { compile 'org.codehaus.groovy:groovy-all' compile 'org.springframework.boot:spring-boot-starter-web' }
  • 12. Environments and Profiles • Put application.properties/application.yml somewhere in classpath • Easy one: src/main/resources folder 12 app: name: Springboot+Config+Yml+Demo version: 1.0.0 server: port: 8080 --- spring: profiles: development server: port: 9001 application.yml app.name=Springboot+Config+Demo app.version=1.0.0 server.port=8080 application.properties app.name=Springboot+Config+Demo app.version=1.0.0 server.port=8080 application-development.properties
  • 13. Examples 13 export SPRING_PROFILES_ACTIVE=development export SERVER_PORT=8090 gradle bootRun java -jar build/libs/demo-1.0.0.jar java -jar -Dspring.profiles.active=development build/libs/dem-1.0.0.jar java -jar -Dserver.port=8090 build/libs/demo-1.0.0.jar OS env variable with a -D argument (remember to put it before the main class or jar archive)
  • 14. Binding properties 14 import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @Component @ConfigurationProperties(prefix = "app") class AppInfo { String name String version } Using ConfigurationProperties annotation import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component @Component class AppConfig { @Value('${app.name}') String appName @Value('${server.port}') Integer port } Using Value annotation
  • 15. Packaging executable jar and war files 15 $ gradle build $ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar //... apply plugin: 'war' war { baseName = 'myapp' version = '0.5.0' } //.... configurations { providedRuntime } dependencies { compile("org.springframework.boot:spring-boot-starter-web") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") // ... } $ gradle war Packaging as jar with embedded tomcat Packaging as war : configure build.groovy
  • 16. Miscellaneous - Enabling Disabling the Banner - Changing the Banner - Adding event Listeners - Logging startup info
  • 17.
  • 18. Takeaways ● Idea behind Spring Boot. ● It’s Core Features. ● Easy start with Spring Boot using CLI. ● Starter POMs. ● Using Spring boot with one of the build tools - gradle. ● Packaging executable jar files / war files. ● Some Misc.