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 Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
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
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 

What's hot (20)

Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring boot
Spring bootSpring boot
Spring boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
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
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 

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

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

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