SlideShare a Scribd company logo
Spring Boot -
A Microframework for
Microservices
Nilanjan Roy
What is Spring Boot ?
• Focuses attention at a single point (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
What is Spring Boot
How Does it help microservices ?
• You are going to write more than one microservice
• That means you are going to do this a lot….
– Declare dependencies
– Configure Spring
– Configure logging
– Load properties file
– Setup monitoring
– Add Security
– Talk to a database
– Add metrics
Spring Boot Modules
Spring Boot Modules
• 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
Spring Boot Starter POMs
Spring Boot Actuator: Production-
ready features
Gaining application insight with
Actuator
• Spring Boot Actuator adds several helpful management endpoints
to a Spring Boot-based application. These endpoints include
• GET /autoconfig —Explains the decisions made by Spring Boot when
applying autoconfiguration
• GET /beans —Catalogs the beans that are configured for the running
application
• GET /configprops —Lists all properties available for configuring the
properties of beans in the application with their current values
• GET /dump —Lists application threads, including a stack trace for
each thread
Gaining application insight with
the Actuator
• GET /env —Lists all environment and system property variables available to
the application context
• GET /env/{name} —Displays the value for a specific environment or
property variable
• GET /health —Displays the current application health
• GET /info —Displays application-specific information
• GET /metrics —Lists metrics concerning the application, including running
counts of requests against certain endpoints
• GET /metrics/{name} —Displays metrics for a specific application metric
key
• POST /shutdown —Forcibly shuts down the application
• GET /trace —Lists metadata concerning recent requests served through the
application, including request and response headers
Extending The Actuator
Extending The Actuator
Monitoring MicroServices
Monitoring MicroServices
Customizing Monitoring Endpoints
• We can change how those endpoints are exposed
using application.properties
– management.port=8081 - you can expose those endpoints on port
other than the one application is using .
– management.address=127.0.0.1 - you can only allow to access by IP
address (localhost here).
– management.context-path=/actuator - allows you to have those
endpoints grouped under specified context path rather than root,
i.e. /actuator/health.
– endpoints.health.enabled=false - allows to enable/disable specified
endpoint by name, here /health is disabled.
Customizing Monitoring Endpoints
• We can change if an endpoint is enabled, if it is considered sensitive and even
its id.
• Following entry in the application.properties that changes the sensitivity and id
of the beans endpoint and also enables shutdown.
endpoints.beans.id=springbeans
endpoints.beans.sensitive=false
endpoints.shutdown.enabled=true
• By default, all endpoints except for shutdown are enabled. If you prefer to
specifically “opt-in” endpoint enablement you can use
the endpoints.enabled property. For example, the following will
disable all endpoints except for info:
endpoints.enabled=false
endpoints.info.enabled=true
Securing Monitoring Endpoints
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
• Disable basic security in application.properties, so that it leaves only the
sensitive Actuator endpoints secured and leaves the rest open for access:
– security.basic.enabled=false
• Set up a new username, or a password if you don't want it to be different on
each start:
– security.user.name=admin
– security.user.password=new_password
• In case you're using the security features across the application and decided to
secure those endpoints yourself, you can disable default security for Actuator:
– management.security.enabled=false
Custom Healthchecks
• Besides checking if the application is UP or DOWN, which is done by
default, you can add checks for things like database connectivity or MQ
status etc.
@Component
public class MyHealth implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0)
{
return Health.down().withDetail("Error Code",
errorCode).build();
}
return Health.up().build();
}
}
Measure Everything with Metrics
Emitting your own Metrics
• GaugeService :
– A service that can be used to submit a named double value for storage
and analysis.
– For instance, the value submitted here could be a method execution
timing result, and it would go to a backend that keeps a histogram of
recent values for comparison purposes.
• CounterService :
– Increment , decrement or reset an integer value (e.g. number of times
an error was thrown)
Storing Metrics
Logging with Spring Boot
Logging with Spring Boot
• Spring Boot uses Commons Logging for all internal logging, but
leaves the underlying log implementation open. Default
configurations are provided for Java Util Logging,Log4J and Logback.
In each case there is console output and file output (rotating, 10
Mb file size).
• By default, If we use the ‘Starter POMs’, Logback will be used for
logging. Appropriate Logback routing is also included to ensure that
dependent libraries that use Java Util Logging, Commons Logging,
Log4J or SLF4J will all work correctly.
Spring Boot AutoConfiguration
• Spring Boot auto-configuration attempts to automatically configure your
Spring application based on the jar dependencies that you have added.
For example, If HSQLDB is on your classpath, and you have not manually
configured any database connection beans, then it will auto-configure an
in-memory database.
• You need to opt-in to auto-configuration by adding
the @EnableAutoConfiguration or @SpringBootApplication annotations to
one of your @Configurationclasses.
• Disabling AutoConfiguration
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration { }
Understanding AutoConfiguration
Behind the Scene
• There are two parts to it :
1) List of files which has to be considered as
configuration classes
2) When these should be applied
Behind the Scene
• @EnableAutoConfiguration" is a spring-boot(autoconfigure) annotation
which is handled by
org.springframework.boot.autoconfigure.EnableAutoConfigurationImport
Selector.
• In "EnableAutoConfigurationImportSelector", it uses
"org.springframework.core.io.support.SpringFactoriesLoader#loadFactory
Names" from spring-core to load configurations whose key is
"org.springframework.boot.autoconfigure.EnableAutoConfiguration".
• This method reads "META-INF/spring.factories" from jar files.(multiple jar
files can have "spring.factories" and when they have same key, comma
delimited values will be merged.)
Understand @Conditional
Understand “Twelve-Factor App”
style configuration
Understand “Twelve-Factor App”
style configuration
• Spring Boot builds upon propertySource
• It allows you to externalize your configuration so you can work with the
same application code in different environments. You can use properties
files, YAML files, environment variables and command-line arguments to
externalize configuration.
• Spring Boot uses a very particular PropertySource order that is designed
to allow sensible overriding of values, properties are considered in the
following order:
Understand “Twelve-Factor App”
style configuration
Understand “Twelve-Factor App”
style configuration
Set the active Spring profiles :
• Profile-specific application properties outside of your packaged jar
(application-{profile}.properties and YAML variants)
• Profile-specific application properties packaged inside your jar
(application-{profile}.properties and YAML variants)
– Usually set through system profile (spring.profiles.active) or an OS environment variable
(SPRING_PROFILES_ACTIVE).
e.g. $ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
or it can be set in application.properties :
spring.profiles.active=production
Spring FrameWork profiles for
Multiple Environments
Relaxed Bindings
Common application properties
• http://docs.spring.io/spring-
boot/docs/current/reference/html/common-
application-properties.html
Understand “Twelve-Factor App”
style configuration
• @ConfigurationProperties
– A way to map properties to POJO
– Type Safe
– IDE Support
– Can be validated with @Valid
Creates Runnable Fat JARs
The executable jar file structure
example.jar
|
+-META-INF
| +-MANIFEST.MF
+-org
| +-springframework
| +-boot
| +-loader
| +-<spring boot loader classes>
+-com
| +-mycompany
| + project
| +-YouClasses.class
+-lib
+-dependency1.jar
+-dependency2.jar
References & Further readings
• http://docs.spring.io/spring-
boot/docs/current-
SNAPSHOT/reference/htmlsingle/
• http://cloud.spring.io/spring-cloud-netflix/

More Related Content

What's hot (20)

PDF
PUC SE Day 2019 - SpringBoot
JosuĂŠ Neis
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PDF
REST APIs with Spring
Joshua Long
 
PPTX
Spring Boot and REST API
07.pallav
 
PPT
Spring Boot in Action
Alex Movila
 
ODP
Xke spring boot
sourabh aggarwal
 
PPTX
Mongo db
Gyanendra Yadav
 
PDF
Building a Spring Boot Application - Ask the Audience!
🎤 Hanno Embregts 🎸
 
PPTX
Spring Boot Tutorial
Naphachara Rattanawilai
 
PDF
Introduction to Spring Boot!
Jakub Kubrynski
 
PDF
Gradle - Build System
Jeevesh Pandey
 
PPTX
The Past Year in Spring for Apache Geode
VMware Tanzu
 
PPTX
Spring Boot & WebSocket
Ming-Ying Wu
 
PPTX
Spring Boot Showcase
Naphachara Rattanawilai
 
KEY
Multi Client Development with Spring
Joshua Long
 
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
PDF
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
PDF
The Spring Update
Gunnar Hillert
 
PDF
Ansible with oci
DonghuKIM2
 
PDF
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 
PUC SE Day 2019 - SpringBoot
JosuĂŠ Neis
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
REST APIs with Spring
Joshua Long
 
Spring Boot and REST API
07.pallav
 
Spring Boot in Action
Alex Movila
 
Xke spring boot
sourabh aggarwal
 
Mongo db
Gyanendra Yadav
 
Building a Spring Boot Application - Ask the Audience!
🎤 Hanno Embregts 🎸
 
Spring Boot Tutorial
Naphachara Rattanawilai
 
Introduction to Spring Boot!
Jakub Kubrynski
 
Gradle - Build System
Jeevesh Pandey
 
The Past Year in Spring for Apache Geode
VMware Tanzu
 
Spring Boot & WebSocket
Ming-Ying Wu
 
Spring Boot Showcase
Naphachara Rattanawilai
 
Multi Client Development with Spring
Joshua Long
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
The Spring Update
Gunnar Hillert
 
Ansible with oci
DonghuKIM2
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 

Viewers also liked (19)

PPTX
Developing Agile Java Applications using Spring tools
Sathish Chittibabu
 
PPTX
Introduction to AJAX and DWR
SweNz FixEd
 
PPTX
Hibernate Training Session1
Asad Khan
 
PPTX
JSON-(JavaScript Object Notation)
Skillwise Group
 
PPT
Hibernate
husnara mohammad
 
PDF
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
PDF
Spring Boot Actuator
Rowell Belen
 
PPT
Maven Overview
FastConnect
 
PPTX
Spring boot actuator
Choonghyun Yang
 
PDF
A pattern language for microservices (#gluecon #gluecon2016)
Chris Richardson
 
PPT
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
PPTX
Json
Shyamala Prayaga
 
PDF
Microservices + Events + Docker = A Perfect Trio (dockercon)
Chris Richardson
 
PDF
Developing microservices with aggregates (SpringOne platform, #s1p)
Chris Richardson
 
PDF
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Fahad Golra
 
PDF
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Chris Richardson
 
PPSX
JDBC: java DataBase connectivity
Tanmoy Barman
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PPTX
Spring boot
sdeeg
 
Developing Agile Java Applications using Spring tools
Sathish Chittibabu
 
Introduction to AJAX and DWR
SweNz FixEd
 
Hibernate Training Session1
Asad Khan
 
JSON-(JavaScript Object Notation)
Skillwise Group
 
Hibernate
husnara mohammad
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
Spring Boot Actuator
Rowell Belen
 
Maven Overview
FastConnect
 
Spring boot actuator
Choonghyun Yang
 
A pattern language for microservices (#gluecon #gluecon2016)
Chris Richardson
 
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Chris Richardson
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Chris Richardson
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Fahad Golra
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Chris Richardson
 
JDBC: java DataBase connectivity
Tanmoy Barman
 
Spring Framework - Core
Dzmitry Naskou
 
Spring boot
sdeeg
 
Ad

Similar to Spring boot for buidling microservices (20)

PPT
"Spring Boot. Boot up your development" Сергей Моренец
Fwdays
 
PPT
Spring Boot. Boot up your development. JEEConf 2015
Strannik_2013
 
PPTX
Module 6 _ Spring Boot for java application to begin
Deepakprasad838637
 
PPT
Spring Boot. Boot up your development
Strannik_2013
 
PPTX
Beginner's guide to Springboot - Actuator
techaiaiai
 
PPTX
Spring boot
Gyanendra Yadav
 
PPTX
Spring.new hope.1.3
Alex Tumanoff
 
PPTX
Spring.Boot up your development
Strannik_2013
 
PDF
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
PPTX
Spring boot
jacob benny john
 
PPTX
cadec-2016-spring-boot-for-understanding-the-core-concepts.pptx
imjdabhinawpandey
 
PDF
Spring Boot Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
Spring Boot Whirlwind Tour
VMware Tanzu
 
PPTX
Spring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel Lavoie
VMware Tanzu
 
PDF
Spring and Pivotal Application Service - SpringOne Tour Dallas
VMware Tanzu
 
PPTX
Bootify your spring application
Jimmy Lu
 
PDF
Spring Boot & Spring Cloud on Pivotal Application Service
VMware Tanzu
 
PPTX
Spring on PAS - Fabio Marinelli
VMware Tanzu
 
"Spring Boot. Boot up your development" Сергей Моренец
Fwdays
 
Spring Boot. Boot up your development. JEEConf 2015
Strannik_2013
 
Module 6 _ Spring Boot for java application to begin
Deepakprasad838637
 
Spring Boot. Boot up your development
Strannik_2013
 
Beginner's guide to Springboot - Actuator
techaiaiai
 
Spring boot
Gyanendra Yadav
 
Spring.new hope.1.3
Alex Tumanoff
 
Spring.Boot up your development
Strannik_2013
 
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
Spring boot
jacob benny john
 
cadec-2016-spring-boot-for-understanding-the-core-concepts.pptx
imjdabhinawpandey
 
Spring Boot Interview Questions PDF By ScholarHat
Scholarhat
 
Spring Boot Whirlwind Tour
VMware Tanzu
 
Spring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel Lavoie
VMware Tanzu
 
Spring and Pivotal Application Service - SpringOne Tour Dallas
VMware Tanzu
 
Bootify your spring application
Jimmy Lu
 
Spring Boot & Spring Cloud on Pivotal Application Service
VMware Tanzu
 
Spring on PAS - Fabio Marinelli
VMware Tanzu
 
Ad

Recently uploaded (20)

PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 

Spring boot for buidling microservices

  • 1. Spring Boot - A Microframework for Microservices Nilanjan Roy
  • 2. What is Spring Boot ? • Focuses attention at a single point (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
  • 4. How Does it help microservices ? • You are going to write more than one microservice • That means you are going to do this a lot…. – Declare dependencies – Configure Spring – Configure logging – Load properties file – Setup monitoring – Add Security – Talk to a database – Add metrics
  • 6. Spring Boot Modules • 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
  • 8. Spring Boot Actuator: Production- ready features
  • 9. Gaining application insight with Actuator • Spring Boot Actuator adds several helpful management endpoints to a Spring Boot-based application. These endpoints include • GET /autoconfig —Explains the decisions made by Spring Boot when applying autoconfiguration • GET /beans —Catalogs the beans that are configured for the running application • GET /configprops —Lists all properties available for configuring the properties of beans in the application with their current values • GET /dump —Lists application threads, including a stack trace for each thread
  • 10. Gaining application insight with the Actuator • GET /env —Lists all environment and system property variables available to the application context • GET /env/{name} —Displays the value for a specific environment or property variable • GET /health —Displays the current application health • GET /info —Displays application-specific information • GET /metrics —Lists metrics concerning the application, including running counts of requests against certain endpoints • GET /metrics/{name} —Displays metrics for a specific application metric key • POST /shutdown —Forcibly shuts down the application • GET /trace —Lists metadata concerning recent requests served through the application, including request and response headers
  • 15. Customizing Monitoring Endpoints • We can change how those endpoints are exposed using application.properties – management.port=8081 - you can expose those endpoints on port other than the one application is using . – management.address=127.0.0.1 - you can only allow to access by IP address (localhost here). – management.context-path=/actuator - allows you to have those endpoints grouped under specified context path rather than root, i.e. /actuator/health. – endpoints.health.enabled=false - allows to enable/disable specified endpoint by name, here /health is disabled.
  • 16. Customizing Monitoring Endpoints • We can change if an endpoint is enabled, if it is considered sensitive and even its id. • Following entry in the application.properties that changes the sensitivity and id of the beans endpoint and also enables shutdown. endpoints.beans.id=springbeans endpoints.beans.sensitive=false endpoints.shutdown.enabled=true • By default, all endpoints except for shutdown are enabled. If you prefer to specifically “opt-in” endpoint enablement you can use the endpoints.enabled property. For example, the following will disable all endpoints except for info: endpoints.enabled=false endpoints.info.enabled=true
  • 17. Securing Monitoring Endpoints <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> • Disable basic security in application.properties, so that it leaves only the sensitive Actuator endpoints secured and leaves the rest open for access: – security.basic.enabled=false • Set up a new username, or a password if you don't want it to be different on each start: – security.user.name=admin – security.user.password=new_password • In case you're using the security features across the application and decided to secure those endpoints yourself, you can disable default security for Actuator: – management.security.enabled=false
  • 18. Custom Healthchecks • Besides checking if the application is UP or DOWN, which is done by default, you can add checks for things like database connectivity or MQ status etc. @Component public class MyHealth implements HealthIndicator { @Override public Health health() { int errorCode = check(); // perform some specific health check if (errorCode != 0) { return Health.down().withDetail("Error Code", errorCode).build(); } return Health.up().build(); } }
  • 20. Emitting your own Metrics • GaugeService : – A service that can be used to submit a named double value for storage and analysis. – For instance, the value submitted here could be a method execution timing result, and it would go to a backend that keeps a histogram of recent values for comparison purposes. • CounterService : – Increment , decrement or reset an integer value (e.g. number of times an error was thrown)
  • 23. Logging with Spring Boot • Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open. Default configurations are provided for Java Util Logging,Log4J and Logback. In each case there is console output and file output (rotating, 10 Mb file size). • By default, If we use the ‘Starter POMs’, Logback will be used for logging. Appropriate Logback routing is also included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly.
  • 24. Spring Boot AutoConfiguration • Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, If HSQLDB is on your classpath, and you have not manually configured any database connection beans, then it will auto-configure an in-memory database. • You need to opt-in to auto-configuration by adding the @EnableAutoConfiguration or @SpringBootApplication annotations to one of your @Configurationclasses. • Disabling AutoConfiguration @Configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyConfiguration { }
  • 26. Behind the Scene • There are two parts to it : 1) List of files which has to be considered as configuration classes 2) When these should be applied
  • 27. Behind the Scene • @EnableAutoConfiguration" is a spring-boot(autoconfigure) annotation which is handled by org.springframework.boot.autoconfigure.EnableAutoConfigurationImport Selector. • In "EnableAutoConfigurationImportSelector", it uses "org.springframework.core.io.support.SpringFactoriesLoader#loadFactory Names" from spring-core to load configurations whose key is "org.springframework.boot.autoconfigure.EnableAutoConfiguration". • This method reads "META-INF/spring.factories" from jar files.(multiple jar files can have "spring.factories" and when they have same key, comma delimited values will be merged.)
  • 30. Understand “Twelve-Factor App” style configuration • Spring Boot builds upon propertySource • It allows you to externalize your configuration so you can work with the same application code in different environments. You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration. • Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values, properties are considered in the following order:
  • 32. Understand “Twelve-Factor App” style configuration Set the active Spring profiles : • Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants) • Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants) – Usually set through system profile (spring.profiles.active) or an OS environment variable (SPRING_PROFILES_ACTIVE). e.g. $ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar or it can be set in application.properties : spring.profiles.active=production
  • 33. Spring FrameWork profiles for Multiple Environments
  • 35. Common application properties • http://docs.spring.io/spring- boot/docs/current/reference/html/common- application-properties.html
  • 36. Understand “Twelve-Factor App” style configuration • @ConfigurationProperties – A way to map properties to POJO – Type Safe – IDE Support – Can be validated with @Valid
  • 38. The executable jar file structure example.jar | +-META-INF | +-MANIFEST.MF +-org | +-springframework | +-boot | +-loader | +-<spring boot loader classes> +-com | +-mycompany | + project | +-YouClasses.class +-lib +-dependency1.jar +-dependency2.jar
  • 39. References & Further readings • http://docs.spring.io/spring- boot/docs/current- SNAPSHOT/reference/htmlsingle/ • http://cloud.spring.io/spring-cloud-netflix/