Slide 1

Slide 1 text

Migrating to Spring Boot 2 and Webflux Gotchas migrating to Spring Boot 2 and Demo Migration from MVC to Webflux by @trevorgowing hosted by @travelstart

Slide 2

Slide 2 text

Introduction

Slide 3

Slide 3 text

Features of Spring and Boot ● Core Tech [IOC, events, resources, i18n, validation, data binding, type conversion, SpEL, AOP] ● Testing [Mocks, TestContext, MockMVC, WebTestClient] ● Data Access [TX, DAO, JDBC, ORM, XML] ● Integration [remoting, JMS, JCA, JMX, email, tasks, scheduling, cache] ● Web [MVC, WebFlux] ● Languages [Kotlin, Groovy] ● Stand-alone application ● Embed Tomcat, Jetty or Undertow ● Opinionated 'starter' dependencies ● Automatic configuration ● Production-ready features [metrics, health checks, externalized configuration] ● No code gen or XML

Slide 4

Slide 4 text

A little about me

Slide 5

Slide 5 text

What I have been doing recently? ● Developed 2 - 1.x ● Migrated 3 - 1.x -> 2.0 ○ 1 - Maven -> Gradle ● Migrated 1 - Traditional deployment (web.xml & application.xml) -> 2.0 (Java Config) ● Developed 0 - Webflux ● spring-boot-starter-web ● spring-boot-starter-json ● spring-boot-starter-amqp ● spring-boot-starter-security ● spring-boot-starter-data-jpa ● spring-boot-starter-actuator ● spring-boot-starter-data-redis ● spring-boot-starter-web-services

Slide 6

Slide 6 text

History Time

Slide 7

Slide 7 text

Spring Framework & Boot Release History ● 1.0 - March 2004 ● 2.0 - November 2006 ● 3.0 - June 2010 ● 4.0 - December 2013 ● 5.0 - September 2017 ● 5.0.7 - June 2018 - Latest ● 1.0 - April 2014 ● 1.1 - June 2014 ● 1.2 - December 2014 ● 1.3 - November 2015 ● 1.4 - July 2016 ● 1.5.1 - January 2017 ● 2.0 - March 2018 ● 2.0.3 - June 2018 - Latest

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Dependency upgrades 1.2.x - > 1.3.x ● Spring Framework 4.1.9 -> 4.2.8 ● Spring Security 3.2.9 -> 4.0.4

Slide 10

Slide 10 text

Spring Security 3.x -> 4.0 Gotchas ● Default filter paths renamed e.g. `/j_spring_security_logout` -> `/logout` ● Overriding default response headers no longer disables all unless explicitly specified ● Roles are automatically prefixed with “ROLE_”

Slide 11

Slide 11 text

Dependency upgrades 1.3.x -> 1.4.x ● Elasticsearch 1.5.2 -> 2.4.5 ● Hibernate 4.3.11 -> 5.0.12 ● MongoDB 2.13.3 -> 3.2.2 ● Solr 4.10 -> 5.5 ● Spring Data Gosling SR5 -> Hopper SR11 ● Spring Framework 4.2.8 -> 4.3.9 (Requires Jackson 2.6+) ● Spring Security 4.0.4 -> 4.1.4 ● Tomcat 8.0.37 -> 8.5.15 (BIO Connector, Comet, JSR-77, InstanceListener removed)

Slide 12

Slide 12 text

Hibernate 4.x -> 5.0 Gotchas ● ‘hibernate.id.new_generator_mappings’ property default changed to true. ○ `spring.jpa.hibernate.use-new-id-generator-mapping` defaults to false ● NamingStrategy split in two: ○ ImplicitNamingStrategy - used whenever a table or column is not explicitly named ○ PhysicalNamingStrategy - used to convert a "logical name" into a physical name ● I experienced this silently creating new tables, that were not previously explicitly named in combination with ddl-auto = update.

Slide 13

Slide 13 text

Hibernate Id Generation Strategy for MySQL ● Default Id generation strategy changed from Identity to Table when using Auto generation strategy with MySQL. Table strategy not recommend. Hibernate 4.x Hibernate 5.x

Slide 14

Slide 14 text

Dependency upgrades 1.4.x -> 1.5.x ● Gradle 1.2 -> 2.9 (Groovy 1.8 -> 2.3.2) ● Spring Data Hopper SR11 -> Ingalls SR13 ● Spring Security 4.14 -> 4.2.7

Slide 15

Slide 15 text

Actuator 1.4.x -> 1.5.x Gotchas ● Sensitive endpoints are now secured by default (even without spring-security) ○ Override with: `management.security.enabled=false` ● Default role changed from ‘ADMIN’ to ‘ACTUATOR’ ○ override with: `management.security.roles={ROLE}`

Slide 16

Slide 16 text

2 . 0

Slide 17

Slide 17 text

Dependency upgrades 1.5 -> 2.0 ● Flyway 3.2.1 -> 5.0.7 (Java 8, Maven 3 & Gradle 3 Baselines, Java 9 & Cockroach Support) ● Gradle 2.9 -> 4.x ● Java 8 baseline & Java 9 support ● Hibernate 5.0.12 -> 5.2.17 ● Mockito 1.10.19 -> 2.15.0 (argThat moved to org.mockito.hamcrest.MockitoHamcrest) ● Spring Data Ingalls SR13 -> Kay SR8 ○ (Java 8, Framework 5, Reactive [Mongo, Redis, Couch, Cassandra], Java 9 Support) ● Spring Framework and Security 4.x.x -> 5.0.x ● Thymeleaf 2.1.6 -> 3.0.9 (https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html)

Slide 18

Slide 18 text

Changes and Gotchas ● Default JDBC connection pool: Tomcat - > Hikari ● Gradle plugin rewritten ○ Spring Boot & Dependency Management plugins separated ○ BootJar & BootWar tasks replace BootRepackage and extend Java Jar & War tasks ○ BootRun extends JavaExec ● Properties ○ A number of properties have been renamed, replaced or re-namespaced ○ Relaxed binding has been tightened ○ Org.springframework.boot.bind package has been removed & replaced by new binding api (see https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0)

Slide 19

Slide 19 text

Changes and Gotchas continued... ● Web starters e.g. thymeleaf no longer transitively depend on starter-web ● Jackson JSR-310 dates now written as ISO8601 strings by default ○ Restore previous behaviour ‘spring.jackson.serialization.write-dates-as-timestamps=true’ ● HTTP suffix pattern matching is disabled by default ○ GET /proj/spring-boot.json will no longer map to @GetMapping(“/proj/spring-boot) ● ‘spring.jpa.hibernate.use-new-id-generator-mappings’ now defaults to true ● Data repository method signature changes ○ e.g. T findOne(T id) -> Optional findById(T id)

Slide 20

Slide 20 text

New Features ● HTTP/2 Support (Web Server specific) ● Kotlin 1.2 Support ● Thymeleaf javax.time support ● Jackson & Java 8 data types packaged in ‘spring-boot-starter-json’

Slide 21

Slide 21 text

Actuator 1.5 -> 2.0 ● Technology agnostic: MVC or Webflux ● Request & Response structure changes ● Read/Write Model -> CRUD Model ● Config with `endpoints.{name}.enabled` & `endpoints.{name}.sensitive` properties -> `management.endpoints.web.exposure.include` ● Custom security -> Spring Security ● Mapped under `/` -> Mapped under `/actuator` ● Custom metrics -> Micrometer.io

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

A little about Reactive

Slide 24

Slide 24 text

Reactive Streams Specification

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Project Reactor

Slide 28

Slide 28 text

Spring Web - MVC and/or Webflux

Slide 29

Slide 29 text

Enough talking, demo time! https://github.com/trevorgowing/spring-boot-migration

Slide 30

Slide 30 text

But is it faster?

Slide 31

Slide 31 text

2500 Concurrent Users

Slide 32

Slide 32 text

5000 Concurrent Users

Slide 33

Slide 33 text

10000 Concurrent Users

Slide 34

Slide 34 text

References - Migration ● https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migrati on-Guide ● https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Releas e-Notes ● https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Releas e-Notes ● https://vladmihalcea.com/why-should-not-use-the-auto-jpa-generationtype- with-mysql-and-hibernate/ ● https://vladmihalcea.com/why-you-should-never-use-the-table-identifier-gen erator-with-jpa-and-hibernate/

Slide 35

Slide 35 text

References - Spring Boot 2 ● https://docs.spring.io/spring-boot/docs/current/reference/html/ ● https://www.brighttalk.com/webcast/14893/304441/introducing-spring-bo ot-2-0 ● https://github.com/philwebb/spring-boot-2-webinar ● http://www.baeldung.com/new-spring-boot-2 ● http://www.baeldung.com/spring-boot-actuators ● http://www.baeldung.com/spring-security-5-reactive

Slide 36

Slide 36 text

References - Reactive & Reactor ● https://www.reactivemanifesto.org/ ● http://www.reactive-streams.org/ ● https://projectreactor.io/ ● https://spring.io/blog/2016/06/07/notes-on-reactive-programming-part-i-th e-reactive-landscape ● https://spring.io/blog/2016/06/13/notes-on-reactive-programming-part-ii-wr iting-some-code ● https://spring.io/blog/2016/07/20/notes-on-reactive-programming-part-iii-a- simple-http-server-application ● https://spring.io/blog/2016/04/19/understanding-reactive-types

Slide 37

Slide 37 text

References - Webflux ● https://docs.spring.io/spring/docs/current/spring-framework-reference/we b-reactive.html ● http://www.baeldung.com/spring-5 ● http://www.baeldung.com/spring-security-5-reactive ● https://www.journaldev.com/20763/spring-webflux-reactive-programming ● https://acuriouscoder.net/spring-webflux-annotation-based/ ● http://javasampleapproach.com/spring-framework/spring-webflux/springbo ot-webflux-annotation-based-programming-model ● https://dzone.com/articles/annotated-controllers-spring-webwebflux-and-te stin

Slide 38

Slide 38 text

References - Other ● https://medium.com/@the.raj.saxena/springboot-2-performance-servlet-sta ck-vs-webflux-reactive-stack-528ad5e9dadc ● https://www.romaniancoder.com/book-review-clean-architecture-by-robert- c-martin/ ● http://www.sportingnews.com/au/football/news/2018-fifa-world-cup-who-i s-off-to-russia-who-missed-out/13kxz8c09i2s516e8v0esdl6mf