Skip to content

Book-Microservices-v2/update-2.7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published