Xke spring boot

sourabh aggarwal
sourabh aggarwalTechnology Lead at Ephesoft, Inc. em Ephesoft, Inc.
By : Jaspereet Juneja & Sourabh Aggarwal
Date : 30 July 2015
SPRING BOOT
What is Spring Boot?
● Spring Boot is a approach to develop Spring based application
with very less or no configuration.
● It leverages existing Spring projects as well as Third party
projects to develop production ready applications.
● It provides a set of Starter Pom’s, gradle etc.. build files which
one can use to add required dependencies and also facilitate
auto configuration. Depending on the libraries on its classpath,
Spring Boot automatically configures required classes.
● For example to interact with DB, if there is Spring Data libraries
on class path then it automatically sets up connection to DB
along with the Data Source class.
Spring Boot focus point?
Why to use spring boot?
➔ Create stand-alone Spring applications
➔ Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
➔ Provide opinionated 'starter' POMs to simplify your Maven configuration
➔ Automatically configure Spring whenever possible
➔ Provide production-ready features such as metrics, health checks and
externalized configuration
➔ Absolutely no code generation and no requirement for XML configuration.
Spring Boot Modules?
Boot
Autoconfigure
Starters
CLI
Actuator
Tools
Samples
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 Actuator?
● It’s a Spring Boot module that immediately gives your Spring-based web applications basic health
check and monitoring interfaces. To use it just add Maven dependency spring-boot-starter-actuator.
● If you now recompile and restart your service, you’ll notice that a lot more endpoints are being
mapped (this is printed to the log during startup). Some of these are:
– /health – returns “ok” as text/plain content which is useful for simple service monitoring
– /env – check environment configuration, property file and command line argument overrides, active profiles
– /metrics – basic statistics on your service endpoints (e.g. hit count, error count)
– /dump – thread dump
– /trace – the latest HTTP request/response pairs
● You can access/modify (or change completely if you wish) the behavior for most of these. For
example, if you want to add a custom metric, just inject a MetricRepository in your business beans,
and start using it, it’ll get exposed via the Actuator /metrics interface.
Spring Boot over Spring
● Opinionated Convention Over Configuration
● Automatic Configuration
● Starter + Example Builds
● Standalone Apps
● No XML!
● Embedded Containers
● Metrics (Actuator)
● Groovy
Hello World(Java)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
public class MyApplication {
@RequestMapping("/hello")
public String sayHello() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
@EnableAutoConfiguration
● Attempts to auto-configure your application
● Backs off as you define your own beans
@Configuration
@EnableAutoConfiguration
public class MyApplication {
}
Starter POMs
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
● Standard Maven POMs
● Define dependencies that we recommend
● Parent optional
● Available for web, batch, integration, data, amqp, aop, jdbc, ...
● e.g. data = hibernate + spring-data + JSR 303
Packaging For Production
Maven plugin (using spring-boot-starter-parent):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
$ mvn package
Annotations
We are relying on Spring’s annotation and package-scan based
approach to configure our controller
● @EnableAutoConfiguration is specific to Spring Boot and declaring it
will result in a lot of pre-defined configuration pulled to our Spring
Application Context (like the embedded Tomcat container)
● SpringApplication is another Boot-specific component, it’s the default
entry point for most of the Spring Boot applications and will take care of
the Spring Application Context for us.
● And that is all you actually need. At this point you should be able to start
this application from your favourite IDE, launching class
HelloConfiguration. Then visit http://localhost:8080/hello which should
result in “Hello World!” being displayed in your browser.
Problems?
Although most features that Spring Boot gives you are extremely useful and work very well
immediately, we encountered a few cases where a bit of caution is recommended:
– Spring Boot will import and use Logback and SLF4J as default loggers. If you want to use something else (e.g.
Log4J) or one of your dependencies transitively imports it, you need to be careful and use the appropriate logger
bridges. Some combinations may result in your applications not starting at all. Maven exclusions for transitive
dependencies will come handy.
– The Spring Boot Maven Builder packages executable jar files in a specific way, effectively adding multiple levels of
nested jar files. This is a problem if your libraries want to extract contents from the nested jar files as Java won’t be
able to resolve that resource path. Consider using a different packaging mechanism like Shade or AppAssembler
in such cases. Spring Boot Maven Parent comes with a basic configuration for Shade, but the preferred choice
should be the Boot-builder.
– We advise some level of caution if you want to use embedded application servers and JSPs with Spring Boot,
there may be some limitations.
Overriding default configuration
● Using property files?
● Overriding with command line arguments?
● Support for Spring profiles?
● Overriding default beans?
Using property files?
●
By default Spring Boot will look for a property file in the package root directory called
application.properties, this is a good place to customize your application. By Maven
conventions, place this file into the src/main/resources directory so your build artefacts will be
generated correctly. For example let’s set the contents to:
server.port=11000
● This will cause the embedded Tomcat to listen on port 11000 instead of 8080. If you now
restart your service, you should use http://localhost:11000/hello to get access.
●
Finding out what is given by default and what you can override is probably the biggest
problem with Spring Boot at the moment. There is no comprehensive documentation about all
the options, but the code in org.springframework.boot.autoconfigure.* packages is a good
starting point. (e.g. server.port is bound to a field in
org.springframework.boot.autoconfigure.web.ServerProperties as of Boot 1.0.0.RC3).
Overriding with command line
arguments?
● If you need more execution-specific parameter use, you can do
it. The usual convention of the property overriding chain: defaults
< property files < Java VM arguments is still valid, but Spring
Boot will also give you Spring’s command-line argument
property source: with double dashes (“–”) arguments when
executing your application, you can specify property overrides:
$ java -jar spring-boot-example-0.0.1-SNAPSHOT.jar
--server.port=12000
● As you probably have already figured out, this will result in your
webserver listening on port 12000 and your application available
on http://localhost:12000/hello
Support for Spring profiles?
● Spring Boot actively supports the usage of Spring Profiles.
First, to activate a profile, you can use the double-dash
command line argument syntax: –spring.profiles.active and
list those that you want activated. Additionally, you can name
your property files in the following way:
application-{profile}.properties
● And only those that match one of the active profiles will get
loaded.
● Regarding your Spring beans, you can rely on the @Profile
annotation to work as expected.
Overriding default beans
● When pulling a spring-boot-starter project as a dependency,
Boot will declare the most commonly needed beans. For
example, in case of a web project, you will get a
DispatcherServlet without having to do anything (usually, you
can configure these default beans with externalized
properties).
● In the majority of the cases this will be sufficient. However, if
you want to have more control over these beans, just declare
them as you normally would and your beans will override the
ones given by Boot (in fact, Boot won’t even instantiate any of
its default beans if you have an overriding bean).
Xke spring boot
1 de 20

Recomendados

Spring Boot Tutorial por
Spring Boot TutorialSpring Boot Tutorial
Spring Boot TutorialNaphachara Rattanawilai
7.8K visualizações29 slides
Spring Boot por
Spring BootSpring Boot
Spring BootHongSeong Jeon
3.9K visualizações41 slides
Spring boot por
Spring bootSpring boot
Spring bootPradeep Shanmugam
648 visualizações12 slides
Spring boot introduction por
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
7.7K visualizações36 slides
Introduction to Spring Boot por
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootTrey Howard
656 visualizações17 slides
Spring boot por
Spring bootSpring boot
Spring bootsdeeg
26.6K visualizações25 slides

Mais conteúdo relacionado

Mais procurados

Introduction to Spring Boot! por
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
6.4K visualizações28 slides
Introduction to Spring Boot por
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootPurbarun Chakrabarti
1.1K visualizações18 slides
Spring Boot por
Spring BootSpring Boot
Spring BootJaran Flaath
545 visualizações51 slides
Spring boot - an introduction por
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
1.9K visualizações17 slides
Spring boot Introduction por
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
3.1K visualizações26 slides
Spring boot por
Spring bootSpring boot
Spring bootGyanendra Yadav
1.9K visualizações32 slides

Mais procurados(20)

Introduction to Spring Boot! por Jakub Kubrynski
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski6.4K visualizações
Introduction to Spring Boot por Purbarun Chakrabarti
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti1.1K visualizações
Spring Boot por Jaran Flaath
Spring BootSpring Boot
Spring Boot
Jaran Flaath545 visualizações
Spring boot - an introduction por Jonathan Holloway
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway1.9K visualizações
Spring boot Introduction por Jeevesh Pandey
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey3.1K visualizações
Spring boot por Gyanendra Yadav
Spring bootSpring boot
Spring boot
Gyanendra Yadav1.9K visualizações
Spring Boot por Jiayun Zhou
Spring BootSpring Boot
Spring Boot
Jiayun Zhou2.5K visualizações
Spring Boot and REST API por 07.pallav
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav673 visualizações
PUC SE Day 2019 - SpringBoot por Josué Neis
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis701 visualizações
Spring Boot por koppenolski
Spring BootSpring Boot
Spring Boot
koppenolski365 visualizações
Springboot introduction por Sagar Verma
Springboot introductionSpringboot introduction
Springboot introduction
Sagar Verma141 visualizações
Introduction to spring boot por Santosh Kumar Kar
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar19.6K visualizações
Spring Framework - AOP por Dzmitry Naskou
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou8.4K visualizações
Spring - Part 1 - IoC, Di and Beans por Hitesh-Java
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java1.3K visualizações
Spring Boot por Pei-Tang Huang
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang4.3K visualizações
Connecting Connect with Spring Boot por Vincent Kok
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
Vincent Kok1.1K visualizações
Spring User Guide por Muthuselvam RS
Spring User GuideSpring User Guide
Spring User Guide
Muthuselvam RS3.7K visualizações
Spring Framework por tola99
Spring Framework  Spring Framework
Spring Framework
tola991.2K visualizações
Spring Boot & Actuators por VMware Tanzu
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
VMware Tanzu4.6K visualizações

Similar a Xke spring boot

Spring boot for buidling microservices por
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservicesNilanjan Roy
1.2K visualizações39 slides
Spring boot jpa por
Spring boot jpaSpring boot jpa
Spring boot jpaHamid Ghorbani
920 visualizações19 slides
Rediscovering Spring with Spring Boot(1) por
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Gunith Devasurendra
428 visualizações36 slides
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf por
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
3 visualizações36 slides
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf por
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfAppster1
2 visualizações36 slides
Spring Boot por
Spring BootSpring Boot
Spring BootJaydeep Kale
47 visualizações21 slides

Similar a Xke spring boot(20)

Spring boot for buidling microservices por Nilanjan Roy
Spring boot for buidling microservicesSpring boot for buidling microservices
Spring boot for buidling microservices
Nilanjan Roy1.2K visualizações
Spring boot jpa por Hamid Ghorbani
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani920 visualizações
Rediscovering Spring with Spring Boot(1) por Gunith Devasurendra
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra428 visualizações
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf por Appster1
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
Appster13 visualizações
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf por Appster1
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster12 visualizações
Spring Boot por Jaydeep Kale
Spring BootSpring Boot
Spring Boot
Jaydeep Kale47 visualizações
Spring Boot Whirlwind Tour por VMware Tanzu
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
VMware Tanzu464 visualizações
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017) por 🎤 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)
🎤 Hanno Embregts 🎸738 visualizações
Building a Spring Boot Application - Ask the Audience! por 🎤 Hanno Embregts 🎸
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 🎸917 visualizações
Spring boot por jacob benny john
Spring bootSpring boot
Spring boot
jacob benny john530 visualizações
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018) por 🎤 Hanno Embregts 🎸
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 🎸279 visualizações
Springboot2 postgresql-jpa-hibernate-crud-example with test por HyukSun Kwon
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon105 visualizações
Enterprise Build And Test In The Cloud por Carlos Sanchez
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
Carlos Sanchez6.1K visualizações
Apache Maven - eXo VN office presentation por Arnaud Héritier
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentation
Arnaud Héritier565 visualizações
Using Maven2 por elliando dias
Using Maven2Using Maven2
Using Maven2
elliando dias812 visualizações
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid... por London Microservices
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
London Microservices52 visualizações
Spring and DWR por wiradikusuma
Spring and DWRSpring and DWR
Spring and DWR
wiradikusuma2.1K visualizações
Maven Introduction por Sandeep Chawla
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla21.2K visualizações
Spring boot vs spring framework razor sharp web applications por Katy Slemon
Spring boot vs spring framework razor sharp web applicationsSpring boot vs spring framework razor sharp web applications
Spring boot vs spring framework razor sharp web applications
Katy Slemon79 visualizações

Mais de sourabh aggarwal

Mongo production Sharded cluster por
Mongo production Sharded clusterMongo production Sharded cluster
Mongo production Sharded clustersourabh aggarwal
107 visualizações8 slides
Mule Complete Training por
Mule Complete TrainingMule Complete Training
Mule Complete Trainingsourabh aggarwal
2.8K visualizações88 slides
Spring 4 advanced final_xtr_presentation por
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
650 visualizações48 slides
Spring 4 final xtr_presentation por
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
869 visualizações43 slides
Hibernate complete Training por
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
1.3K visualizações45 slides
Liferay with xebia por
Liferay with xebiaLiferay with xebia
Liferay with xebiasourabh aggarwal
791 visualizações18 slides

Mais de sourabh aggarwal(6)

Mongo production Sharded cluster por sourabh aggarwal
Mongo production Sharded clusterMongo production Sharded cluster
Mongo production Sharded cluster
sourabh aggarwal107 visualizações
Mule Complete Training por sourabh aggarwal
Mule Complete TrainingMule Complete Training
Mule Complete Training
sourabh aggarwal2.8K visualizações
Spring 4 advanced final_xtr_presentation por sourabh aggarwal
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
sourabh aggarwal650 visualizações
Spring 4 final xtr_presentation por sourabh aggarwal
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
sourabh aggarwal869 visualizações
Hibernate complete Training por sourabh aggarwal
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
sourabh aggarwal1.3K visualizações
Liferay with xebia por sourabh aggarwal
Liferay with xebiaLiferay with xebia
Liferay with xebia
sourabh aggarwal791 visualizações

Último

Optimizing Communication to Optimize Human Behavior - LCBM por
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBMYaman Kumar
38 visualizações49 slides
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue por
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueShapeBlue
135 visualizações13 slides
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... por
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...BookNet Canada
41 visualizações16 slides
CryptoBotsAI por
CryptoBotsAICryptoBotsAI
CryptoBotsAIchandureddyvadala199
40 visualizações5 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue por
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
147 visualizações23 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue por
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
222 visualizações7 slides

Último(20)

Optimizing Communication to Optimize Human Behavior - LCBM por Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 visualizações
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue por ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue135 visualizações
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... por BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 visualizações
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue por ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue147 visualizações
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue por ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue222 visualizações
"Node.js Development in 2024: trends and tools", Nikita Galkin por Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays32 visualizações
"Package management in monorepos", Zoltan Kochan por Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays33 visualizações
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 por BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 visualizações
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... por ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue194 visualizações
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld35 visualizações
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... por ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue126 visualizações
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT por ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue206 visualizações
The Role of Patterns in the Era of Large Language Models por Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li85 visualizações
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... por ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue119 visualizações
Initiating and Advancing Your Strategic GIS Governance Strategy por Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software176 visualizações
Qualifying SaaS, IaaS.pptx por Sachin Bhandari
Qualifying SaaS, IaaS.pptxQualifying SaaS, IaaS.pptx
Qualifying SaaS, IaaS.pptx
Sachin Bhandari1K visualizações
"Surviving highload with Node.js", Andrii Shumada por Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays56 visualizações
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... por ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue139 visualizações

Xke spring boot

  • 1. By : Jaspereet Juneja & Sourabh Aggarwal Date : 30 July 2015 SPRING BOOT
  • 2. What is Spring Boot? ● Spring Boot is a approach to develop Spring based application with very less or no configuration. ● It leverages existing Spring projects as well as Third party projects to develop production ready applications. ● It provides a set of Starter Pom’s, gradle etc.. build files which one can use to add required dependencies and also facilitate auto configuration. Depending on the libraries on its classpath, Spring Boot automatically configures required classes. ● For example to interact with DB, if there is Spring Data libraries on class path then it automatically sets up connection to DB along with the Data Source class.
  • 4. Why to use spring boot? ➔ Create stand-alone Spring applications ➔ Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files) ➔ Provide opinionated 'starter' POMs to simplify your Maven configuration ➔ Automatically configure Spring whenever possible ➔ Provide production-ready features such as metrics, health checks and externalized configuration ➔ Absolutely no code generation and no requirement for XML configuration.
  • 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
  • 7. Spring Boot Actuator? ● It’s a Spring Boot module that immediately gives your Spring-based web applications basic health check and monitoring interfaces. To use it just add Maven dependency spring-boot-starter-actuator. ● If you now recompile and restart your service, you’ll notice that a lot more endpoints are being mapped (this is printed to the log during startup). Some of these are: – /health – returns “ok” as text/plain content which is useful for simple service monitoring – /env – check environment configuration, property file and command line argument overrides, active profiles – /metrics – basic statistics on your service endpoints (e.g. hit count, error count) – /dump – thread dump – /trace – the latest HTTP request/response pairs ● You can access/modify (or change completely if you wish) the behavior for most of these. For example, if you want to add a custom metric, just inject a MetricRepository in your business beans, and start using it, it’ll get exposed via the Actuator /metrics interface.
  • 8. Spring Boot over Spring ● Opinionated Convention Over Configuration ● Automatic Configuration ● Starter + Example Builds ● Standalone Apps ● No XML! ● Embedded Containers ● Metrics (Actuator) ● Groovy
  • 9. Hello World(Java) import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration public class MyApplication { @RequestMapping("/hello") public String sayHello() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
  • 10. @EnableAutoConfiguration ● Attempts to auto-configure your application ● Backs off as you define your own beans @Configuration @EnableAutoConfiguration public class MyApplication { }
  • 11. Starter POMs <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ● Standard Maven POMs ● Define dependencies that we recommend ● Parent optional ● Available for web, batch, integration, data, amqp, aop, jdbc, ... ● e.g. data = hibernate + spring-data + JSR 303
  • 12. Packaging For Production Maven plugin (using spring-boot-starter-parent): <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> $ mvn package
  • 13. Annotations We are relying on Spring’s annotation and package-scan based approach to configure our controller ● @EnableAutoConfiguration is specific to Spring Boot and declaring it will result in a lot of pre-defined configuration pulled to our Spring Application Context (like the embedded Tomcat container) ● SpringApplication is another Boot-specific component, it’s the default entry point for most of the Spring Boot applications and will take care of the Spring Application Context for us. ● And that is all you actually need. At this point you should be able to start this application from your favourite IDE, launching class HelloConfiguration. Then visit http://localhost:8080/hello which should result in “Hello World!” being displayed in your browser.
  • 14. Problems? Although most features that Spring Boot gives you are extremely useful and work very well immediately, we encountered a few cases where a bit of caution is recommended: – Spring Boot will import and use Logback and SLF4J as default loggers. If you want to use something else (e.g. Log4J) or one of your dependencies transitively imports it, you need to be careful and use the appropriate logger bridges. Some combinations may result in your applications not starting at all. Maven exclusions for transitive dependencies will come handy. – The Spring Boot Maven Builder packages executable jar files in a specific way, effectively adding multiple levels of nested jar files. This is a problem if your libraries want to extract contents from the nested jar files as Java won’t be able to resolve that resource path. Consider using a different packaging mechanism like Shade or AppAssembler in such cases. Spring Boot Maven Parent comes with a basic configuration for Shade, but the preferred choice should be the Boot-builder. – We advise some level of caution if you want to use embedded application servers and JSPs with Spring Boot, there may be some limitations.
  • 15. Overriding default configuration ● Using property files? ● Overriding with command line arguments? ● Support for Spring profiles? ● Overriding default beans?
  • 16. Using property files? ● By default Spring Boot will look for a property file in the package root directory called application.properties, this is a good place to customize your application. By Maven conventions, place this file into the src/main/resources directory so your build artefacts will be generated correctly. For example let’s set the contents to: server.port=11000 ● This will cause the embedded Tomcat to listen on port 11000 instead of 8080. If you now restart your service, you should use http://localhost:11000/hello to get access. ● Finding out what is given by default and what you can override is probably the biggest problem with Spring Boot at the moment. There is no comprehensive documentation about all the options, but the code in org.springframework.boot.autoconfigure.* packages is a good starting point. (e.g. server.port is bound to a field in org.springframework.boot.autoconfigure.web.ServerProperties as of Boot 1.0.0.RC3).
  • 17. Overriding with command line arguments? ● If you need more execution-specific parameter use, you can do it. The usual convention of the property overriding chain: defaults < property files < Java VM arguments is still valid, but Spring Boot will also give you Spring’s command-line argument property source: with double dashes (“–”) arguments when executing your application, you can specify property overrides: $ java -jar spring-boot-example-0.0.1-SNAPSHOT.jar --server.port=12000 ● As you probably have already figured out, this will result in your webserver listening on port 12000 and your application available on http://localhost:12000/hello
  • 18. Support for Spring profiles? ● Spring Boot actively supports the usage of Spring Profiles. First, to activate a profile, you can use the double-dash command line argument syntax: –spring.profiles.active and list those that you want activated. Additionally, you can name your property files in the following way: application-{profile}.properties ● And only those that match one of the active profiles will get loaded. ● Regarding your Spring beans, you can rely on the @Profile annotation to work as expected.
  • 19. Overriding default beans ● When pulling a spring-boot-starter project as a dependency, Boot will declare the most commonly needed beans. For example, in case of a web project, you will get a DispatcherServlet without having to do anything (usually, you can configure these default beans with externalized properties). ● In the majority of the cases this will be sufficient. However, if you want to have more control over these beans, just declare them as you normally would and your beans will override the ones given by Boot (in fact, Boot won’t even instantiate any of its default beans if you have an overriding bean).