Partner – Microsoft – NPI (cat= Spring)
announcement - icon

Azure Spring Apps is a fully managed service from Microsoft (built in collaboration with VMware), focused on building and deploying Spring Boot applications on Azure Cloud without worrying about Kubernetes.

And, the Enterprise plan comes with some interesting features, such as commercial Spring runtime support, a 99.95% SLA and some deep discounts (up to 47%) when you are ready for production.

>> Learn more and deploy your first Spring Boot app to Azure.

You can also ask questions and leave feedback on the Azure Spring Apps GitHub page.

1. Overview

In this tutorial, we’ll show how to deploy an application from our Bootstrap a Simple Application using Spring Boot tutorial to App Engine on Google Cloud Platform.

As part of this we’ll:

  • Configure Google Cloud Platform Console and SDK
  • Use Cloud SQL to create a MySQL instance
  • Configure the application for Spring Cloud GCP
  • Deploy the application to App Engine and test it

2. Google Cloud Platform Configuration

We can use the GCP Console to get our local environment ready for GCP. We can find the installation process on the official website.

Let’s create a project on GCP using the GCP Console:

gcloud init

Next, let’s configure the project name:

gcloud config set project baeldung-spring-boot-bootstrap

Then we’ll install the App Engine support and create an App Engine instance:

gcloud components install app-engine-java
gcloud app create

Our application will need to connect to a MySQL database within the Cloud SQL environment. As Cloud SQL doesn’t provide a free tier we’ll have to enable billing on the GCP account.

We can check available tiers easily:

gcloud sql tiers list

Before continuing, we should use the GCP Website to enable the Cloud SQL Admin API.

Now we can create a MySQL instance and database in Cloud SQL using the Cloud Console or the SDK CLI. During this process, we’ll choose the region and provide an instance name and database name. It’s important that the app and the database instance are in the same region.

Since we’re going to deploy the app to europe-west2, let’s do the same for the instance:

# create instance
gcloud sql instances create \
  baeldung-spring-boot-bootstrap-db \
    --tier=db-f1-micro \
# create database
gcloud sql databases create \
  baeldung_bootstrap_db \

3. Spring Cloud GCP Dependencies

Our application will need dependencies from the Spring Cloud GCP project for the cloud-native APIs. For this, let’s use a Maven profile named cloud-gcp:


Then we add the App Engine Maven plugin:


4. Application Configuration

Now, let’s define the configuration that allows the application to use the cloud-native resources like the database.

Spring Cloud GCP uses to determine the application name:

We’ll use a Spring Profile named gcp for this deployment and we’ll need to configure the database connection. Therefore we create src/main/resources/\

5. Deployment

The Google App Engine provides two Java environments:

  • the Standard environment provides Jetty and JDK8 and the Flexible environment provides just JDK8 and
  • the Flexible environment is the best option for Spring Boot applications.

We require the gcp and mysql Spring profiles to be active, so we provide the SPRING_PROFILES_ACTIVE environmental variable to the application by adding it to the deployment configuration in src/main/appengine/app.yaml:

runtime: java
env: flex
  jdk: openjdk8
- url: /.*
  script: this field is required, but ignored
  instances: 1

Now, let’s build and deploy the application using the appengine maven plugin:

mvn clean package appengine:deploy -P cloud-gcp

After deployment we can view or tail log files:

# view
gcloud app logs read

# tail
gcloud app logs tail

Now, let’s verify that our application is working by adding a book:

http POST \
        title="The Player of Games" author="Iain M. Banks"

Expecting the following output:

HTTP/1.1 201 
    "author": "Iain M. Banks",
    "id": 1,
    "title": "The Player of Games"

6. Scaling the Application

The default scaling in App Engine is automatic.

It may be better to start with manual scaling until we understand the runtime behavior, and the associated budgets and costs involved. We can assign resources to the application and configure automatic scaling in app.yaml:

# Application Resources
  cpu: 2
  memory_gb: 2
  disk_size_gb: 10
  - name: ramdisk1
    volume_type: tmpfs
    size_gb: 0.5
# Automatic Scaling
  min_num_instances: 1 
  max_num_instances: 4 
  cool_down_period_sec: 180 
    target_utilization: 0.6

7. Conclusion

In this tutorial, we:

  • Configured Google Cloud Platform and the App Engine
  • Created a MySQL instance with Cloud SQL
  • Configured Spring Cloud GCP for using MySQL
  • Deployed our configured Spring Boot application, and
  • Tested and scaled the application

We can always refer to Google’s extensive App Engine documentation for further details.

The complete source code of our examples here is, as always, over on GitHub.

Course – LS (cat=Spring)

Get started with Spring and Spring Boot, through the Learn Spring course:

res – Microservices (eBook) (cat=Cloud/Spring Cloud)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.