Giter Site home page Giter Site logo

update-2.7's Introduction

Book Extra Chapters - U.2.7: Upgrade to Spring Boot 2.7.1

This repository contains the source code of the practical use case described in the book Learn Microservices with Spring Boot (2nd Edition).

If you want to know more details about the book and its extra chapters, make sure to visit this page.

The book follows a pragmatic approach to building a Microservice Architecture, using a reference implementation that evolves from a small monolith to a full microservice system.

Upgrade - Spring Boot 2.7

This extra chapter brings the project dependencies to the Spring Boot 2.7.1 version.

All these changes are described in detail in a blog post at The Practical Developer's website. Visit https://thepracticaldeveloper.com/book-update-2.7.1/

Major H2 upgrade with Spring Boot 2.7

The Spring Boot 2.7 release has upgraded H2 to a new major version, 2.x. Many changes are backwards incompatible and two of them break our code.

Feature not supported: "AUTO_SERVER=TRUE && DB_CLOSE_ON_EXIT=FALSE"

These two features can't be used together anymore. See the blog post for more details.

Solved by removing the DB_CLOSE_ON_EXIT parameter from the connection URL.

Error executing DDL "create table user ..."

More detailed error:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table [*]user (id bigint not null, alias varchar(255), primary key (id))"; expected "identifier"; SQL statement: [...]

Reason: user is now a keyword, so it conflicts with the table name. Fix (one of the possibilities): Add NON_KEYWORDS=USER; to the connection URL for the multiplication microservice's database.

See the blog post for a complete explanation.

New configuration approach (changed in 2.4)

In addition to the mandatory upgrades to make the code work with 2.7, I also switched to the new configuration approach introduced by Spring Boot 2.4.x.

Required changes to move to the new configuration approach in 2.4:

  • Remove the legacy bootstrap starter (if previously added, in my case it was)
  • Remove the bootstrap.properties or bootstrap.yml and move all those properties to the application.properties or application.yml.
  • For Spring Cloud Consul to work fine, add a spring.config.import=consul: property (or the YAML equivalent) to the projects using Consul.
  • We can remove all the test.properties files and the @TestPropertySource annotation pointing to it that we needed to add for backwards compatibility with the bootstrap legacy mode.

All the details here

Bonus: using an H2 server instead of an auto-server

This version also includes an H2 server Docker image so the microservices can use H2 as an isolated database server instead of using the shared database files offered by the AUTO_SERVER mode.

Check the blog post for the instructions.

Bonus: remove the ugly error related to MacOS DNS resolver for Netty

To remove this error for good, I added the native DNS dependency for my local setup. This applies to the gateway service's pom.xml:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-resolver-dns-native-macos</artifactId>
    <!-- Change this if your Mac is not M1, see e.g. https://stackoverflow.com/questions/65954571/spring-boot-2-4-2-dns-resolution-problem-at-start-on-apple-m1 -->
    <classifier>osx-aarch_64</classifier>
    <version>4.1.78.Final</version>
</dependency>

References

Some additional references from the official documentation:

Running the app

You can use Docker to start the complete system, and you can also run the services one by one on your computer. See the book's last chapter repository for the detailed instructions.

Questions

  • Do you have questions about how to make this application work?
  • Did you get the book and have questions about any concept explained within this chapter?
  • Have you found issues using updated dependencies?

Don't hesitate to create an issue in this repository and post your question/problem there.

About the book

Are you interested in building a microservice architecture from scratch? You'll face all the challenges of designing and implementing a distributed system one by one, and will be able to evaluate if it's the best choice for your project.

Buy the book at Amazon, or visit https://tpd.io/book-extra for all the details.

Purchase

You can buy the book online from these stores:

  • Amazon
  • and other online stores, check the IBAN (9781484261309) on google

Source code by chapter (all repositories are available on Github)

Extra chapters:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.