SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Spring
An introduction
Roberto Casadei
Concurrent and Distributed Programming course
Department of Computer Science and Engineering (DISI)
Alma Mater Studiorum – Università of Bologna
June 16, 2018
PCD1718 Introduction Spring Boot 1/12
Outline
1 Introduction
2 Spring Microservices with Spring Boot
PCD1718 Introduction Spring Boot 2/12
Spring » intro
What
Spring: OSS framework that makes it easy to create JVM-based enterprise apps
At its heart is an IoC container (managing beans and their dependencies)
Also, notably: AOP support
Term “Spring” also refers to the family of projects built on top of Spring Framework
Spring Boot: opinionated, CoC-approach for production-ready Spring apps
Spring Cloud: provides tools/patterns for building/deploying µservices
Spring AMQP: supports AMQP-based messaging solutions... many others...
Some History
2003 – Spring sprout as a response to the complexity of the early J2EE specs.
2006 – Spring 2.0 provided XML namespaces and AspectJ support
2007 – Spring 2.5 embraced annotation-driven configuration
Over time, the approach Java enterprise application development has evolved.
Java EE application servers – for full-stack monolithic web-apps
Spring Boot/Cloud apps – for devops/cloud-friendly apps, with embedded server
Spring WebFlux, released with Spring 5 in 2017, supports reactive-stack web apps
PCD1718 Introduction Spring Boot 3/12
Spring » intro
What
Spring: OSS framework that makes it easy to create JVM-based enterprise apps
At its heart is an IoC container (managing beans and their dependencies)
Also, notably: AOP support
Term “Spring” also refers to the family of projects built on top of Spring Framework
Spring Boot: opinionated, CoC-approach for production-ready Spring apps
Spring Cloud: provides tools/patterns for building/deploying µservices
Spring AMQP: supports AMQP-based messaging solutions... many others...
Some History
2003 – Spring sprout as a response to the complexity of the early J2EE specs.
2006 – Spring 2.0 provided XML namespaces and AspectJ support
2007 – Spring 2.5 embraced annotation-driven configuration
Over time, the approach Java enterprise application development has evolved.
Java EE application servers – for full-stack monolithic web-apps
Spring Boot/Cloud apps – for devops/cloud-friendly apps, with embedded server
Spring WebFlux, released with Spring 5 in 2017, supports reactive-stack web apps
PCD1718 Introduction Spring Boot 3/12
Spring » beans and wiring I
(Spring) Bean: application object managed by the Spring IoC container
Configuration metadata tells the Spring container how instantiate, configure,
and assemble the objects in your application.
a) XML-based metadata
b) Java-based configuration
Java-based container configuration
Factory methods in Configuration classes can be annotated with Bean
Configuration public class AppConfig {
Bean public MyService myService() { return new MyServiceImpl(); }
public static void main(String[] args) {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(AppConfig.class);
MyService myService = ctx.getBean(MyService.class);
myService.doStuff();
} }
PCD1718 Introduction Spring Boot 4/12
Spring » beans and wiring II
Spring-managed components
Stereotypes: Component, Service, Controller, Repository
Spring can automatically detect stereotyped classes and register corresponding
BeanDefinitions with the ApplicationContext, via ComponentScan
Configuration
ComponentScan(basePackages="it.unibo.beans")
public class AppConfig { }
package it.unibo.beans;
Service
public class MyService {
Autowired private ServiceA sa; // field injection
public MyService(ServiceB sb){ ... } // constructor injection
Autowired
public void setServiceC(ServiceC sc){ .. } // setter injection
}
PCD1718 Introduction Spring Boot 5/12
Outline
1 Introduction
2 Spring Microservices with Spring Boot
PCD1718 Introduction Spring Boot 6/12
Spring Boot
Spring Boot makes it easy to create stand-alone, production-grade Spring-based
Applications that you can just run
It takes an opinionated view of the Spring platform and 3rd-party libraries
Reasonable convention-over-configuration for getting started quickly
It provides a light version of Spring targeted at Java-based RESTful µservices,
without the need for an external application container
It abstracts away the common REST microservice tasks (routing to business
logic, parsing HTTP params from the URL, mapping JSON to/from POJOs), and
lets the developer focus on the service business logic.
Supported embedded containers: Tomcat 8.5, Jetty 9.4, Undertow 1.4
PCD1718 Introduction Spring Boot 7/12
Build configuration
Build plugins
spring-boot-maven-plugin for Maven
spring-boot-gradle-plugin1
for Gradle
Dependencies (cf., group ID org.springframework.boot)
Starters are a set of convenient dependency descriptors to get a project up and
running quickly.
spring-boot-starter-web: starter for web, RESTful / MVC apps (Tomcat as
default container)
spring-boot-starter-actuator: gives production-ready features for app
monitoring/management
Run
Maven tasks: spring-boot:run, package
Gradle tasks: bootRun, bootJar
1https:
//docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/
PCD1718 Introduction Spring Boot 8/12
Hello Spring Boot
SpringBootApplication // tells Boot this is the bootstrap class
public class MyApp {
public static void main(String[] args){
SpringApplication.run(MyApp.class, args);
}
}
SpringBootApplication also implies
– EnableAutoConfiguration: tells Spring Boot to "guess" config by classpath
– ComponentScan: tells Spring to look for components
RestController RequestMapping(value="/app")
public class MyController {
RequestMapping(value="/hello/{name}", method = RequestMethod.GET)
public String hello( PathVariable("name") String name){
return "Hello, " + name;
}
}
Endpoint: http://localhost:8080/app/hello/Boot
Actuator also exposes http://localhost:8080/actuator/health
PCD1718 Introduction Spring Boot 9/12
A path for learning Spring Boot I
Spring Guides: https://spring.io/guides
Do-It-Yourself
Building an Application with Spring Boot
https://spring.io/guides/gs/spring-boot/
Use RestController and RequestMapping to add endpoints.
Create a SpringBootApplication class with main method.
Consuming a RESTful Web Service
https://spring.io/guides/gs/consuming-rest/
You use RestTemplate to make calls to RESTful services
You can use RestTemplateBuilder to build RestTemplate Beans as needed.
Building a Reactive RESTful Web Service (with Spring WebFlux)
https://spring.io/guides/gs/reactive-rest-service/
(Optional) Creating Asynchronous Methods
https://spring.io/guides/gs/async-method/
Declare Async methods (so they’ll run on a separate thread) that return
CompletableFuture<T>.
Annotate your app with EnableAsync and define an Executor Bean
PCD1718 Introduction Spring Boot 10/12
A path for learning Spring Boot II
(Optional) Messaging with RabbitMQ
https://spring.io/guides/gs/messaging-rabbitmq/
(Optional) Messaging with Redis
https://spring.io/guides/gs/messaging-redis/
Start redis: redis-server (default on port 6379)
You need to configure (i) a connection factory to connect to the Redis server; (ii) a
message listener container for registering receivers; and (iii) a Redis template to
send messages.
If the listener is a POJO, it needs to be wrapped in a MessageListenerAdapter.
(Optional) Accessing Data Reactively with Redis
https://spring.io/guides/gs/spring-data-reactive-redis/
Create a configuration class with Spring Beans supporting reactive Redis
operations—cf., ReactiveRedisOperations<K,V>
Inject ReactiveRedisOperations<K,V> to interface with Redis
(Optional) Scheduling Tasks
https://spring.io/guides/gs/scheduling-tasks/
EnableScheduling + Scheduled on a Component’s method.
PCD1718 Introduction Spring Boot 11/12
References
References I
PCD1718 Appendix 12/12

Mais conteúdo relacionado

Mais procurados

Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Getting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA releaseGetting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA release
VMware Tanzu
 

Mais procurados (20)

Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring hibernate tutorial
Spring hibernate tutorialSpring hibernate tutorial
Spring hibernate tutorial
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Getting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA releaseGetting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA release
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Ready! Steady! SpringBoot!
Ready! Steady! SpringBoot! Ready! Steady! SpringBoot!
Ready! Steady! SpringBoot!
 
Spring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive featuresSpring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive features
 
Introduction to Ibatis by Rohit
Introduction to Ibatis by RohitIntroduction to Ibatis by Rohit
Introduction to Ibatis by Rohit
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfile
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 

Semelhante a Spring Boot: a Quick Introduction

Semelhante a Spring Boot: a Quick Introduction (20)

Spring Boot Whirlwind Tour
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC Seminar
 
javagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platformjavagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platform
 
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 MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
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
 
Spring Mvc,Java, Spring
Spring Mvc,Java, SpringSpring Mvc,Java, Spring
Spring Mvc,Java, Spring
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring Actionscript at Devoxx
Spring Actionscript at DevoxxSpring Actionscript at Devoxx
Spring Actionscript at Devoxx
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Service
 
The next step from Microsoft - Vnext (Srdjan Poznic)
The next step from Microsoft - Vnext (Srdjan Poznic)The next step from Microsoft - Vnext (Srdjan Poznic)
The next step from Microsoft - Vnext (Srdjan Poznic)
 
Spring notes
Spring notesSpring notes
Spring notes
 
Spring tutorials
Spring tutorialsSpring tutorials
Spring tutorials
 
Seven Simple Reasons to Use AppFuse
Seven Simple Reasons to Use AppFuseSeven Simple Reasons to Use AppFuse
Seven Simple Reasons to Use AppFuse
 
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
tutorials-visual-studio_visual-studio-2015-preview-comes-with-emulator-for-an...
tutorials-visual-studio_visual-studio-2015-preview-comes-with-emulator-for-an...tutorials-visual-studio_visual-studio-2015-preview-comes-with-emulator-for-an...
tutorials-visual-studio_visual-studio-2015-preview-comes-with-emulator-for-an...
 

Mais de Roberto Casadei

Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Roberto Casadei
 
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Roberto Casadei
 
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
Introduction to the 1st DISCOLI workshop on distributed collective intelligenceIntroduction to the 1st DISCOLI workshop on distributed collective intelligence
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
Roberto Casadei
 
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Roberto Casadei
 
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Augmented Collective Digital Twins for Self-Organising Cyber-Physical SystemsAugmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Roberto Casadei
 
Tuple-Based Coordination in Large-Scale Situated Systems
Tuple-Based Coordination in Large-Scale Situated SystemsTuple-Based Coordination in Large-Scale Situated Systems
Tuple-Based Coordination in Large-Scale Situated Systems
Roberto Casadei
 
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Roberto Casadei
 
Engineering Resilient Collaborative Edge-enabled IoT
Engineering Resilient Collaborative Edge-enabled IoTEngineering Resilient Collaborative Edge-enabled IoT
Engineering Resilient Collaborative Edge-enabled IoT
Roberto Casadei
 

Mais de Roberto Casadei (20)

Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
 
A Presentation of My Research Activity
A Presentation of My Research ActivityA Presentation of My Research Activity
A Presentation of My Research Activity
 
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
 
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
 
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
 
Aggregate Computing Research: an Overview
Aggregate Computing Research: an OverviewAggregate Computing Research: an Overview
Aggregate Computing Research: an Overview
 
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
Introduction to the 1st DISCOLI workshop on distributed collective intelligenceIntroduction to the 1st DISCOLI workshop on distributed collective intelligence
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
 
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
 
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
FScaFi: A Core Calculus for Collective Adaptive Systems ProgrammingFScaFi: A Core Calculus for Collective Adaptive Systems Programming
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
 
6th eCAS workshop on Engineering Collective Adaptive Systems
6th eCAS workshop on Engineering Collective Adaptive Systems6th eCAS workshop on Engineering Collective Adaptive Systems
6th eCAS workshop on Engineering Collective Adaptive Systems
 
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Augmented Collective Digital Twins for Self-Organising Cyber-Physical SystemsAugmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
 
Tuple-Based Coordination in Large-Scale Situated Systems
Tuple-Based Coordination in Large-Scale Situated SystemsTuple-Based Coordination in Large-Scale Situated Systems
Tuple-Based Coordination in Large-Scale Situated Systems
 
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
 
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
 
Testing: an Introduction and Panorama
Testing: an Introduction and PanoramaTesting: an Introduction and Panorama
Testing: an Introduction and Panorama
 
On Context-Orientation in Aggregate Programming
On Context-Orientation in Aggregate ProgrammingOn Context-Orientation in Aggregate Programming
On Context-Orientation in Aggregate Programming
 
Engineering Resilient Collaborative Edge-enabled IoT
Engineering Resilient Collaborative Edge-enabled IoTEngineering Resilient Collaborative Edge-enabled IoT
Engineering Resilient Collaborative Edge-enabled IoT
 
Aggregate Processes in Field Calculus
Aggregate Processes in Field CalculusAggregate Processes in Field Calculus
Aggregate Processes in Field Calculus
 
AWS and Serverless Computing
AWS and Serverless ComputingAWS and Serverless Computing
AWS and Serverless Computing
 
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Último (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Spring Boot: a Quick Introduction

  • 1. Spring An introduction Roberto Casadei Concurrent and Distributed Programming course Department of Computer Science and Engineering (DISI) Alma Mater Studiorum – Università of Bologna June 16, 2018 PCD1718 Introduction Spring Boot 1/12
  • 2. Outline 1 Introduction 2 Spring Microservices with Spring Boot PCD1718 Introduction Spring Boot 2/12
  • 3. Spring » intro What Spring: OSS framework that makes it easy to create JVM-based enterprise apps At its heart is an IoC container (managing beans and their dependencies) Also, notably: AOP support Term “Spring” also refers to the family of projects built on top of Spring Framework Spring Boot: opinionated, CoC-approach for production-ready Spring apps Spring Cloud: provides tools/patterns for building/deploying µservices Spring AMQP: supports AMQP-based messaging solutions... many others... Some History 2003 – Spring sprout as a response to the complexity of the early J2EE specs. 2006 – Spring 2.0 provided XML namespaces and AspectJ support 2007 – Spring 2.5 embraced annotation-driven configuration Over time, the approach Java enterprise application development has evolved. Java EE application servers – for full-stack monolithic web-apps Spring Boot/Cloud apps – for devops/cloud-friendly apps, with embedded server Spring WebFlux, released with Spring 5 in 2017, supports reactive-stack web apps PCD1718 Introduction Spring Boot 3/12
  • 4. Spring » intro What Spring: OSS framework that makes it easy to create JVM-based enterprise apps At its heart is an IoC container (managing beans and their dependencies) Also, notably: AOP support Term “Spring” also refers to the family of projects built on top of Spring Framework Spring Boot: opinionated, CoC-approach for production-ready Spring apps Spring Cloud: provides tools/patterns for building/deploying µservices Spring AMQP: supports AMQP-based messaging solutions... many others... Some History 2003 – Spring sprout as a response to the complexity of the early J2EE specs. 2006 – Spring 2.0 provided XML namespaces and AspectJ support 2007 – Spring 2.5 embraced annotation-driven configuration Over time, the approach Java enterprise application development has evolved. Java EE application servers – for full-stack monolithic web-apps Spring Boot/Cloud apps – for devops/cloud-friendly apps, with embedded server Spring WebFlux, released with Spring 5 in 2017, supports reactive-stack web apps PCD1718 Introduction Spring Boot 3/12
  • 5. Spring » beans and wiring I (Spring) Bean: application object managed by the Spring IoC container Configuration metadata tells the Spring container how instantiate, configure, and assemble the objects in your application. a) XML-based metadata b) Java-based configuration Java-based container configuration Factory methods in Configuration classes can be annotated with Bean Configuration public class AppConfig { Bean public MyService myService() { return new MyServiceImpl(); } public static void main(String[] args) { ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); MyService myService = ctx.getBean(MyService.class); myService.doStuff(); } } PCD1718 Introduction Spring Boot 4/12
  • 6. Spring » beans and wiring II Spring-managed components Stereotypes: Component, Service, Controller, Repository Spring can automatically detect stereotyped classes and register corresponding BeanDefinitions with the ApplicationContext, via ComponentScan Configuration ComponentScan(basePackages="it.unibo.beans") public class AppConfig { } package it.unibo.beans; Service public class MyService { Autowired private ServiceA sa; // field injection public MyService(ServiceB sb){ ... } // constructor injection Autowired public void setServiceC(ServiceC sc){ .. } // setter injection } PCD1718 Introduction Spring Boot 5/12
  • 7. Outline 1 Introduction 2 Spring Microservices with Spring Boot PCD1718 Introduction Spring Boot 6/12
  • 8. Spring Boot Spring Boot makes it easy to create stand-alone, production-grade Spring-based Applications that you can just run It takes an opinionated view of the Spring platform and 3rd-party libraries Reasonable convention-over-configuration for getting started quickly It provides a light version of Spring targeted at Java-based RESTful µservices, without the need for an external application container It abstracts away the common REST microservice tasks (routing to business logic, parsing HTTP params from the URL, mapping JSON to/from POJOs), and lets the developer focus on the service business logic. Supported embedded containers: Tomcat 8.5, Jetty 9.4, Undertow 1.4 PCD1718 Introduction Spring Boot 7/12
  • 9. Build configuration Build plugins spring-boot-maven-plugin for Maven spring-boot-gradle-plugin1 for Gradle Dependencies (cf., group ID org.springframework.boot) Starters are a set of convenient dependency descriptors to get a project up and running quickly. spring-boot-starter-web: starter for web, RESTful / MVC apps (Tomcat as default container) spring-boot-starter-actuator: gives production-ready features for app monitoring/management Run Maven tasks: spring-boot:run, package Gradle tasks: bootRun, bootJar 1https: //docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/ PCD1718 Introduction Spring Boot 8/12
  • 10. Hello Spring Boot SpringBootApplication // tells Boot this is the bootstrap class public class MyApp { public static void main(String[] args){ SpringApplication.run(MyApp.class, args); } } SpringBootApplication also implies – EnableAutoConfiguration: tells Spring Boot to "guess" config by classpath – ComponentScan: tells Spring to look for components RestController RequestMapping(value="/app") public class MyController { RequestMapping(value="/hello/{name}", method = RequestMethod.GET) public String hello( PathVariable("name") String name){ return "Hello, " + name; } } Endpoint: http://localhost:8080/app/hello/Boot Actuator also exposes http://localhost:8080/actuator/health PCD1718 Introduction Spring Boot 9/12
  • 11. A path for learning Spring Boot I Spring Guides: https://spring.io/guides Do-It-Yourself Building an Application with Spring Boot https://spring.io/guides/gs/spring-boot/ Use RestController and RequestMapping to add endpoints. Create a SpringBootApplication class with main method. Consuming a RESTful Web Service https://spring.io/guides/gs/consuming-rest/ You use RestTemplate to make calls to RESTful services You can use RestTemplateBuilder to build RestTemplate Beans as needed. Building a Reactive RESTful Web Service (with Spring WebFlux) https://spring.io/guides/gs/reactive-rest-service/ (Optional) Creating Asynchronous Methods https://spring.io/guides/gs/async-method/ Declare Async methods (so they’ll run on a separate thread) that return CompletableFuture<T>. Annotate your app with EnableAsync and define an Executor Bean PCD1718 Introduction Spring Boot 10/12
  • 12. A path for learning Spring Boot II (Optional) Messaging with RabbitMQ https://spring.io/guides/gs/messaging-rabbitmq/ (Optional) Messaging with Redis https://spring.io/guides/gs/messaging-redis/ Start redis: redis-server (default on port 6379) You need to configure (i) a connection factory to connect to the Redis server; (ii) a message listener container for registering receivers; and (iii) a Redis template to send messages. If the listener is a POJO, it needs to be wrapped in a MessageListenerAdapter. (Optional) Accessing Data Reactively with Redis https://spring.io/guides/gs/spring-data-reactive-redis/ Create a configuration class with Spring Beans supporting reactive Redis operations—cf., ReactiveRedisOperations<K,V> Inject ReactiveRedisOperations<K,V> to interface with Redis (Optional) Scheduling Tasks https://spring.io/guides/gs/scheduling-tasks/ EnableScheduling + Scheduled on a Component’s method. PCD1718 Introduction Spring Boot 11/12