Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Migrating to Spring Boot 2 and Webflux

Migrating to Spring Boot 2 and Webflux

Release history, dependency changes and gotchas of upgrading Spring Boot.

What's new in Spring Boot 2.

Introduction to Reactive and Spring Webflux.

Trevor Gowing

July 03, 2018
Tweet

More Decks by Trevor Gowing

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. Dependency upgrades 1.2.x - > 1.3.x • Spring Framework 4.1.9

    -> 4.2.8 • Spring Security 3.2.9 -> 4.0.4
  6. 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_”
  7. 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)
  8. 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.
  9. 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
  10. 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
  11. 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}`
  12. 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)
  13. 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)
  14. 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<T> findById(T id)
  15. 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’
  16. 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
  17. 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/
  18. 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
  19. 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
  20. 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