Friday, April 26, 2024
No menu items!
HomeCloud ComputingSpring Cloud GCP 4.0 is out! Let’s upgrade the sample Bank of...

Spring Cloud GCP 4.0 is out! Let’s upgrade the sample Bank of Anthos app!

We’re excited to announce that Spring Cloud GCP version 4.0 is now generally available! In this post, we’ll be describing what the new major version has to offer, and demonstrating the process of using the migration guide on one of our reference architectures, Bank of Anthos.

What’s new?

With this release, Spring Cloud GCP officially supports Spring Boot 3.x. However, this migration involves a number of breaking changes as outlined in the migration guide. The full list of changes made is available on Github, but the one of the most significant differences is that Java 17 is now a minimum requirement.

Another notable feature of this release is the addition of starter artifacts – Spring Boot starters for Google Cloud – that provide dependencies and auto-configurations for 80+ Google Client libraries. Just as the name suggests, these starters can serve as helpful starting points when working with a new client library. For now, they’re in preview. 

These starters are not included in the BOM by default and need to be added as a dependency to your project before they can be used. For example, if you wanted to get started with Cloud Text-to-Speech, you would include the following:

code_block[StructValue([(u’code’, u'<dependency>rn <groupId>com.google.cloud</groupId>rn <artifactId>google-cloud-texttospeech-spring-starter</artifactId>rn <version>4.0.0-preview</version>rn </dependency>’), (u’language’, u”), (u’caption’, <wagtail.wagtailcore.rich_text.RichText object at 0x3e6ce5fdce50>)])]

The upgrade process

We prepared a migration guide to help answer any questions involved with moving from 3.x to 4.x.  Let’s follow those instructions to migrate Bank of Anthos.

We’ll start by cloning and building the application before the upgrade, according to the quickstart and development guide:

code_block[StructValue([(u’code’, u’PROJECT_ID=<YOUR-PROJECT-ID>rngcloud services enable container –project ${PROJECT_ID}rnrngit clone https://github.com/GoogleCloudPlatform/bank-of-anthos.gitrncd bank-of-anthos/rnrngcloud services enable container.googleapis.com monitoring.googleapis.com \rn –project ${PROJECT_ID}rnrnREGION=us-central1rngcloud container clusters create-auto bank-of-anthos \rn –project=${PROJECT_ID} –region=${REGION}rnrngcloud container clusters get-credentials bank-of-anthos \rn –project=${PROJECT_ID} –region=${REGION}rnrnskaffold run –default-repo=gcr.io/${PROJECT_ID}/bank-of-anthos’), (u’language’, u”), (u’caption’, <wagtail.wagtailcore.rich_text.RichText object at 0x3e6ce5fdced0>)])]

At the end of this, you should see a “deployment stabilized” message:

code_block[StructValue([(u’code’, u’Deployments stabilized in 9.657 seconds’), (u’language’, u”), (u’caption’, <wagtail.wagtailcore.rich_text.RichText object at 0x3e6ce5f53e10>)])]

With the environment set up for development, we’re ready to move on to the actual migration. The migration is already complete at time of writing, but here’s the full list of changes made:

We began by checking the current Java, Spring Boot and Spring Cloud GCP versions.

Our Java version is okay, but the other two are out of date, and will need to be updated.
We can also add the Spring Cloud GCP BOM to manage our versions going forward while we’re here.

Then, in no particular order, we can make the following code changes:

Remove the explicit type declarations from our ResponseEntity instantiations.

Replace all javax.* imports with Jakarta.* counterparts, since Spring 3.0 makes use of Jakarta EE 9.0

With those changes in place, the app is upgraded and ready to re-deploy!

Live example

For a finished example of this migration, check out the Bank of Anthos repository on Github. It’s an excellent sample application that showcases a polyglot Java & Python app, served on Kubernetes and Google Cloud. All CI/CD and configurations are open source, so it may be instructive as you approach this migration.

Thanks for reading, and feel free to provide comments or feedback on Twitter, or in the issues section of the repository.

Cloud BlogRead More

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments