SlideShare une entreprise Scribd logo
1  sur  39
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/

Contenu connexe

Tendances

PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 
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 🎸
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeVMware Tanzu
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testHyukSun Kwon
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンharuki ueno
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with ociDonghuKIM2
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 

Tendances (20)

PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Mongo db
Mongo dbMongo db
Mongo db
 
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!
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
Spring Boot Showcase
Spring Boot ShowcaseSpring Boot Showcase
Spring Boot Showcase
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
 
JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
The Spring Update
The Spring UpdateThe Spring Update
The Spring Update
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 

En vedette

Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsSathish Chittibabu
 
Introduction to AJAX and DWR
Introduction to AJAX and DWRIntroduction to AJAX and DWR
Introduction to AJAX and DWRSweNz FixEd
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1Asad Khan
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)Skillwise Group
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot ActuatorRowell Belen
 
A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)Chris Richardson
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkMohit Belwal
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Chris Richardson
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Chris Richardson
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)Fahad Golra
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Chris Richardson
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 

En vedette (19)

Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring tools
 
Introduction to AJAX and DWR
Introduction to AJAX and DWRIntroduction to AJAX and DWR
Introduction to AJAX and DWR
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Hibernate
HibernateHibernate
Hibernate
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Spring boot actuator
Spring boot   actuatorSpring boot   actuator
Spring boot actuator
 
A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Json
JsonJson
Json
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring boot
Spring bootSpring boot
Spring boot
 

Similaire à Spring boot for buidling microservices

Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsmichaelaaron25322
 
Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Externalized Distributed Configuration Management with Spring Cloud Config-Se...Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Externalized Distributed Configuration Management with Spring Cloud Config-Se...Nikhil Hiremath
 
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
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & ActuatorsVMware Tanzu
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your developmentStrannik_2013
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Strannik_2013
 
"Spring Boot. Boot up your development" Сергей Моренец
"Spring Boot. Boot up your development" Сергей Моренец"Spring Boot. Boot up your development" Сергей Моренец
"Spring Boot. Boot up your development" Сергей МоренецFwdays
 
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
 
Gain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring BatchGain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring BatchInexture Solutions
 
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).pdfAppster1
 
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.pdfAppster1
 
Bootify your spring application
Bootify your spring applicationBootify your spring application
Bootify your spring applicationJimmy Lu
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for JavaLars Vogel
 
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
 
Fusion Applications Administration Overview
Fusion Applications Administration OverviewFusion Applications Administration Overview
Fusion Applications Administration OverviewVihangAstik
 

Similaire à Spring boot for buidling microservices (20)

Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Externalized Distributed Configuration Management with Spring Cloud Config-Se...Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Externalized Distributed Configuration Management with Spring Cloud Config-Se...
 
Spring boot wednesday
Spring boot wednesdaySpring boot wednesday
Spring boot wednesday
 
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
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015
 
Spring boot
Spring bootSpring boot
Spring boot
 
"Spring Boot. Boot up your development" Сергей Моренец
"Spring Boot. Boot up your development" Сергей Моренец"Spring Boot. Boot up your development" Сергей Моренец
"Spring Boot. Boot up your development" Сергей Моренец
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Gain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring BatchGain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring Batch
 
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
 
Bootify your spring application
Bootify your spring applicationBootify your spring application
Bootify your spring application
 
Spring Batch
Spring BatchSpring Batch
Spring Batch
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
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
 
Fusion Applications Administration Overview
Fusion Applications Administration OverviewFusion Applications Administration Overview
Fusion Applications Administration Overview
 

Dernier

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Dernier (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

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/