SlideShare a Scribd company logo
1 of 35
Download to read offline
SpringBoot
About us
jneis
josue@townsq.com.br
Josué
Neis
Software
Architect
matheuswanted
matheus.santos@townsq.com.br
Matheus
Santos
Software
Engineer
Agenda
- Java and Spring History
- Spring Framework
- SpringBoot
- IoC and DI
- Spring MVC
- Spring Data
- Next steps
History
J2EE 1.2
Servlet
EJB, JSP, JTA, JMS
J2SE 1.2
Collections
Swing
1996
1997
1998
1999
J2SE 1.1
Java Beans
JDK 1.0
Spring 1.0
J2EE 1.4
JAX-WS
JAX-RPC
2001
2002
2003
2004
interface21
J2EE 1.3
JAXP
Java EE 5
JPA
JAXB (binding)
2005
2006
2006
2007J2SE 5.0
Annotations
Generics
Spring 2.0
XML config
Spring 2.5
Annotation config
Java SE 8
Streams
Optional
Lambda expressions
Functional interfaces
2009
2012
2014
2014Java EE 6
JAX-RS (REST)
CDI (Context and DI)
Bean Validation
Interceptors (AOP)
Spring 3.2
Java config
Spring Boot
Spring 4.0
Java 8
Java EE 7
JSON
Java SE 10
Type inference (local vars)
2017
2017
2018
Java SE 9
Reactive Streams
Spring Boot 2.0
Spring 5.0
Java SE 11
SE-Day
2019
Spring Framework
- OS application framework
- Modular architecture
- Containers: application context, bean factory
- IoC: bean lifecycle management and DI
- AOP: cross-cutting concerns
- MVC: web applications and RESTful services
- Data access: JDBC, ORM, no-SQL
- Transaction management
- Security: authentication and authorization
- Messaging
- Testing
WebData Access & Integration
Core Container
Beans Core Context SpEL
Test
AOP Aspects Instrumentation Messaging
JDBC ORM
JMS Transactions
Servlet
WebSocket
compile group: 'org.springframework', name: 'spring-aop', version: '5.1.7.RELEASE'
compile group: 'org.springframework', name: 'spring-beans', version: '5.1.7.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.7.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '5.1.7.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.7.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.7.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.1.6.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.5'
compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: '2.9.5'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.1'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.25'
testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.7.RELEASE'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.11.0'
Spring Modules
SpringBoot
- Convention over configuration solution
- Standalone applications (JAR)
- Embedded application servers (no WAR)
- Simplified and auto configuration
- Starters
- Production-ready features
- Metrics
- Health check
- Externalized config
- No code generation
- No XML config required
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
Starters
Spring Initializr
IoC & DI
- Inversion of Control
- Creationg of objects is transferred to a container or framework
- Decouples execution of tasks from their implementations
- Improves modularity (different implementations)
- Improves testability (isolating and mocking components)
- Dependency Injection
- Pattern that implements IoC principle
- Control being inverted is setting of objects' dependencies
public class UserService {
private final UserRepository repository;
public UserService() {
this.repository = new UserRepositoryImpl();
}
}
public class UserService {
private final UserRepository repository;
public UserService(UserRepository repository) {
this.repository = repository;
}
}
IoC & DI
Spring Container
Spring Container
Bean
Bean
Bean
Bean
Bean
Bean
Bean
Object
Object
Object
Object
BeanFactory & ApplicationContext
- BeanFactory
- Container for managing beans
- Resolve object graphs
- XML vs Annotation-based DI
- Component scanning
- ApplicationContext
- Central interface for configuration
- Builds on top of BeanFactory
- Loads file resources
- Publishes lifecycle events to
registered listeners
- Resolves messages for
internationalization
XML vs Annotation-based DI
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<tl;dr>"
xmlns:xsi="<tl;dr>"
xmlns:context="<tl;dr>"
xsi:schemaLocation="<tl;dr>">
<bean id="userRepository"
class="io.townsq.es.day.UserRepositoryImpl"/>
<bean id="userService"
class="io.townsq.es.day.UserService">
<constructor-arg ref="userRepository"/>
</bean>
</beans>
@Configuration
public class BeanConfiguration {
@Bean
public UserRepository userRepository() {
return new UserRepositoryImpl();
}
@Bean
public UserService userService(UserRepository repo) {
return new UserService(repo);
}
}
Component Scanning & Auto-wiring
@Repository
public class UserRepositoryImpl implements UserRepository {
}
@Service
public class UserService {
private final UserRepository repository;
@Autowired
public UserService(UserRepository repository) {
this.repository = repository;
}
}
Spring Container
Spring
Container
Configuration
Metadata
XML-based
Annotation-based
Java-based
Read dependency
and configuration
Create dependency objects
and inject them
Business
Objects
Core Components
WebData Access & Integration
Core Container
Beans Core Context SpEL
Test
AOP Aspects Instrumentation Messaging
JDBC ORM
JMS Transactions
Servlet
WebSocket
Java Servlet
- Java class that
- Handles and processes requests
- Replies a response back
- Managed by Servlet containers
- Application servers
Web Server
JVM
Servlet
Container
Servlet
init()
service()
destroy()
Thread A
Thread B
Request to
Server
HTTP Servlet
@WebServlet(urlPatterns = "/users/*")
public class UserServlet extends HttpServlet {
private final UserService userService = new UserService(new UserRepository() {});
private final ObjectMapper mapper = new ObjectMapper();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String userId = request.getPathInfo().split("/")[1];
User user = userService.getUserById(userId);
response.setContentType("application/json");
response.getWriter().print(mapper.writeValueAsString(user));
response.getWriter().flush();
}
}
MVC in JEE
Client
Controller
Model
View
Request processing
Data validation
Business logic
Data manipulation
Response generation
Rendering
Database
Servlet
JSP
Bean
Request
Response
Browser
Spring MVC
- Web framework built on top of Servlet API
- Request routing and handling
- Object marshalling and validation
- Error handling
Controller
Model
View
Endpoints
JSON
Services
Database
Repositories
Controller @RestController
@RequestMapping("/users")
public class UserController {
@GetMapping("/{userId}")
public User getUserById(@PathVariable Integer userId) {
return service.getUserById(userId);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public User createUser(@RequestBody User user) {
return service.createUser(user);
}
@GetMapping
public Collection<User> listUserByLastName(@RequestParam String lastName) {
return service.listUserByLastName(lastName);
}
}
Error Handling
@RestControllerAdvice
public class ErrorHandler {
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorMessage handle(IllegalArgumentException exception) {
return new ErrorMessage(exception.getMessage());
}
}
JPA
- Specification that describes management of relational data
- Entities:
- Lighweight Java class whose state is persisted to a table in a relational database
- Implementations:
- Hibernate, TopLink, OpenJPA, Spring Data JPA
ORM
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(250) NOT NULL,
first_name VARCHAR(250) NOT NULL,
last_name VARCHAR(250) NOT NULL,
birth_date DATE NOT NULL
);
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, unique = true)
private String email;
private String firstName;
private String lastName;
private LocalDate birthDate;
}
Hibernate
public class UserDao {
public User getById(Integer id) {
SessionFactory factory = HibernateUtil.getSessionFactory();
Session session = factory.openSession();
User user = session.get(User.class, id);
session.close();
return user;
}
}
Spring Data JPA
- Collection of default interfaces that gives
- Most common CRUD operations
- Sorting and paginating features
- Automatic custom querying
- Query DSL for extending query capabilities
- Custom querying with named queries
JPA with Spring Data
public interface UserRepository extends CrudRepository<User, Integer> {
Optional<User> findByEmail(String email);
Collection<User> findAllByLastName(String lastName);
}
public class UserService {
public void doSomething() {
Collection<User> users = repository.findAllByLastName("Banner");
Optional<User> user1 = repository.findByEmail("banner@townsq.io");
Iterable<User> all = repository.findAll();
Optional<User> user2 = repository.findById(1);
User saved = repository.save(new User());
repository.deleteById(2);
}
}
Next Steps
- Spring Security
- Customizable
- Authentication
- Authorization (access control)
- Spring Data with No-SQL
- Mongo
- ElasticSearch
- Cassandra
- Redis
- Spring Webflux
- Functional routing and handling
- Reactive components
- Event loop concurrency model
- Netty
- Reactor
Next Steps
- Spring Cloud
- Cloud-native applications
- Microservices
- Netflix OSS
- Externalized configuration
- Service discovery
- Gateway
- Resilience
- Streams
- Spring with other JVM langs
- Groovy
- Kotlin
Thank you all!
townsq.com.br/trabalhe-conosco
Code is available on:
github.com/townsquad/seday-springboot
Further contact:
josue@townsq.com.br
matheus.santos@townsq.com.br

More Related Content

What's hot

Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCFunnelll
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework IntroductionAnuj Singh Rajput
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 

What's hot (20)

Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 

Similar to PUC SE Day 2019 - SpringBoot

Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New FeaturesJay Lee
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSUFYAN SATTAR
 
Java EE7 Demystified
Java EE7 DemystifiedJava EE7 Demystified
Java EE7 DemystifiedAnkara JUG
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack ImplementationMert Çalışkan
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces Skills Matter
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 UpdateRyan Cuprak
 
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Kazuyuki Kawamura
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7Arun Gupta
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
 
Java ee 7 New Features
Java ee 7   New FeaturesJava ee 7   New Features
Java ee 7 New FeaturesShahzad Badar
 

Similar to PUC SE Day 2019 - SpringBoot (20)

Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Java EE7 Demystified
Java EE7 DemystifiedJava EE7 Demystified
Java EE7 Demystified
 
Jsf Framework
Jsf FrameworkJsf Framework
Jsf Framework
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Java EE 8
Java EE 8Java EE 8
Java EE 8
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
Spring as a Cloud Platform (Developer Summit 2011 17-C-5)
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
Os Haase
Os HaaseOs Haase
Os Haase
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Java ee 7 New Features
Java ee 7   New FeaturesJava ee 7   New Features
Java ee 7 New Features
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

PUC SE Day 2019 - SpringBoot

  • 3. Agenda - Java and Spring History - Spring Framework - SpringBoot - IoC and DI - Spring MVC - Spring Data - Next steps
  • 4. History J2EE 1.2 Servlet EJB, JSP, JTA, JMS J2SE 1.2 Collections Swing 1996 1997 1998 1999 J2SE 1.1 Java Beans JDK 1.0
  • 6. Java EE 5 JPA JAXB (binding) 2005 2006 2006 2007J2SE 5.0 Annotations Generics Spring 2.0 XML config Spring 2.5 Annotation config
  • 7. Java SE 8 Streams Optional Lambda expressions Functional interfaces 2009 2012 2014 2014Java EE 6 JAX-RS (REST) CDI (Context and DI) Bean Validation Interceptors (AOP) Spring 3.2 Java config Spring Boot Spring 4.0 Java 8 Java EE 7 JSON
  • 8. Java SE 10 Type inference (local vars) 2017 2017 2018 Java SE 9 Reactive Streams Spring Boot 2.0 Spring 5.0 Java SE 11 SE-Day 2019
  • 9. Spring Framework - OS application framework - Modular architecture - Containers: application context, bean factory - IoC: bean lifecycle management and DI - AOP: cross-cutting concerns - MVC: web applications and RESTful services - Data access: JDBC, ORM, no-SQL - Transaction management - Security: authentication and authorization - Messaging - Testing
  • 10. WebData Access & Integration Core Container Beans Core Context SpEL Test AOP Aspects Instrumentation Messaging JDBC ORM JMS Transactions Servlet WebSocket
  • 11. compile group: 'org.springframework', name: 'spring-aop', version: '5.1.7.RELEASE' compile group: 'org.springframework', name: 'spring-beans', version: '5.1.7.RELEASE' compile group: 'org.springframework', name: 'spring-context', version: '5.1.7.RELEASE' compile group: 'org.springframework', name: 'spring-core', version: '5.1.7.RELEASE' compile group: 'org.springframework', name: 'spring-web', version: '5.1.7.RELEASE' compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.7.RELEASE' compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.1.6.RELEASE' compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.5' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.5' compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.5' compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: '2.9.5' compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.1' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.25' testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.7.RELEASE' testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0' testCompile group: 'org.assertj', name: 'assertj-core', version: '3.11.0' Spring Modules
  • 12. SpringBoot - Convention over configuration solution - Standalone applications (JAR) - Embedded application servers (no WAR) - Simplified and auto configuration - Starters - Production-ready features - Metrics - Health check - Externalized config - No code generation - No XML config required
  • 13. plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' } apply plugin: 'io.spring.dependency-management' compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' compile group: 'org.springframework.boot', name: 'spring-boot-starter-web' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' Starters Spring Initializr
  • 14. IoC & DI - Inversion of Control - Creationg of objects is transferred to a container or framework - Decouples execution of tasks from their implementations - Improves modularity (different implementations) - Improves testability (isolating and mocking components) - Dependency Injection - Pattern that implements IoC principle - Control being inverted is setting of objects' dependencies
  • 15. public class UserService { private final UserRepository repository; public UserService() { this.repository = new UserRepositoryImpl(); } } public class UserService { private final UserRepository repository; public UserService(UserRepository repository) { this.repository = repository; } } IoC & DI
  • 17. BeanFactory & ApplicationContext - BeanFactory - Container for managing beans - Resolve object graphs - XML vs Annotation-based DI - Component scanning - ApplicationContext - Central interface for configuration - Builds on top of BeanFactory - Loads file resources - Publishes lifecycle events to registered listeners - Resolves messages for internationalization
  • 18. XML vs Annotation-based DI <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="<tl;dr>" xmlns:xsi="<tl;dr>" xmlns:context="<tl;dr>" xsi:schemaLocation="<tl;dr>"> <bean id="userRepository" class="io.townsq.es.day.UserRepositoryImpl"/> <bean id="userService" class="io.townsq.es.day.UserService"> <constructor-arg ref="userRepository"/> </bean> </beans> @Configuration public class BeanConfiguration { @Bean public UserRepository userRepository() { return new UserRepositoryImpl(); } @Bean public UserService userService(UserRepository repo) { return new UserService(repo); } }
  • 19. Component Scanning & Auto-wiring @Repository public class UserRepositoryImpl implements UserRepository { } @Service public class UserService { private final UserRepository repository; @Autowired public UserService(UserRepository repository) { this.repository = repository; } }
  • 20. Spring Container Spring Container Configuration Metadata XML-based Annotation-based Java-based Read dependency and configuration Create dependency objects and inject them Business Objects
  • 21. Core Components WebData Access & Integration Core Container Beans Core Context SpEL Test AOP Aspects Instrumentation Messaging JDBC ORM JMS Transactions Servlet WebSocket
  • 22. Java Servlet - Java class that - Handles and processes requests - Replies a response back - Managed by Servlet containers - Application servers Web Server JVM Servlet Container Servlet init() service() destroy() Thread A Thread B Request to Server
  • 23. HTTP Servlet @WebServlet(urlPatterns = "/users/*") public class UserServlet extends HttpServlet { private final UserService userService = new UserService(new UserRepository() {}); private final ObjectMapper mapper = new ObjectMapper(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = request.getPathInfo().split("/")[1]; User user = userService.getUserById(userId); response.setContentType("application/json"); response.getWriter().print(mapper.writeValueAsString(user)); response.getWriter().flush(); } }
  • 24. MVC in JEE Client Controller Model View Request processing Data validation Business logic Data manipulation Response generation Rendering Database Servlet JSP Bean Request Response Browser
  • 25. Spring MVC - Web framework built on top of Servlet API - Request routing and handling - Object marshalling and validation - Error handling Controller Model View Endpoints JSON Services Database Repositories
  • 26. Controller @RestController @RequestMapping("/users") public class UserController { @GetMapping("/{userId}") public User getUserById(@PathVariable Integer userId) { return service.getUserById(userId); } @PostMapping @ResponseStatus(HttpStatus.CREATED) public User createUser(@RequestBody User user) { return service.createUser(user); } @GetMapping public Collection<User> listUserByLastName(@RequestParam String lastName) { return service.listUserByLastName(lastName); } }
  • 27. Error Handling @RestControllerAdvice public class ErrorHandler { @ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorMessage handle(IllegalArgumentException exception) { return new ErrorMessage(exception.getMessage()); } }
  • 28. JPA - Specification that describes management of relational data - Entities: - Lighweight Java class whose state is persisted to a table in a relational database - Implementations: - Hibernate, TopLink, OpenJPA, Spring Data JPA
  • 29. ORM CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(250) NOT NULL, first_name VARCHAR(250) NOT NULL, last_name VARCHAR(250) NOT NULL, birth_date DATE NOT NULL ); @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column(nullable = false, unique = true) private String email; private String firstName; private String lastName; private LocalDate birthDate; }
  • 30. Hibernate public class UserDao { public User getById(Integer id) { SessionFactory factory = HibernateUtil.getSessionFactory(); Session session = factory.openSession(); User user = session.get(User.class, id); session.close(); return user; } }
  • 31. Spring Data JPA - Collection of default interfaces that gives - Most common CRUD operations - Sorting and paginating features - Automatic custom querying - Query DSL for extending query capabilities - Custom querying with named queries
  • 32. JPA with Spring Data public interface UserRepository extends CrudRepository<User, Integer> { Optional<User> findByEmail(String email); Collection<User> findAllByLastName(String lastName); } public class UserService { public void doSomething() { Collection<User> users = repository.findAllByLastName("Banner"); Optional<User> user1 = repository.findByEmail("banner@townsq.io"); Iterable<User> all = repository.findAll(); Optional<User> user2 = repository.findById(1); User saved = repository.save(new User()); repository.deleteById(2); } }
  • 33. Next Steps - Spring Security - Customizable - Authentication - Authorization (access control) - Spring Data with No-SQL - Mongo - ElasticSearch - Cassandra - Redis - Spring Webflux - Functional routing and handling - Reactive components - Event loop concurrency model - Netty - Reactor
  • 34. Next Steps - Spring Cloud - Cloud-native applications - Microservices - Netflix OSS - Externalized configuration - Service discovery - Gateway - Resilience - Streams - Spring with other JVM langs - Groovy - Kotlin
  • 35. Thank you all! townsq.com.br/trabalhe-conosco Code is available on: github.com/townsquad/seday-springboot Further contact: josue@townsq.com.br matheus.santos@townsq.com.br