Deploy a Spring Boot app to App Engine standard environment

1. Before you begin

App Engine apps are easy to create, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers to maintain. You simply upload your app and it's ready to go.

App Engine apps automatically scale based on incoming traffic. Load balancing, microservices, authorization, SQL and NoSQL databases, memory caching, traffic splitting, logging, search, versioning, rollouts and rollbacks, and security scanning are all supported natively and are highly customizable.

App Engine standard environment and App Engine flexible environment support a host of programming languages, including Java, Python, PHP, NodeJS, and Go. The two environments give developers maximum flexibility with how their app behaves. Each environment has certain strengths. For more information, see Choosing an App Engine environment.

You'll learn to deploy a Spring Boot app to App Engine standard environment. The standard environment scales down to zero instances when no one is using it and automatically scales up!


  • Familiarity with Java programming language and tools
  • Knowledge of standard Linux text editors, such as Vim, Emacs, and nano

What you'll do

  • How to create a Spring Boot Java app on App Engine

What you'll need

2. Setup and requirements

Self-paced environment setup

  1. Sign in to Cloud Console and create a new project or reuse an existing one. If you don't already have a Gmail or Google Workspace account, you must create one.




Remember the project ID, a unique name across all Google Cloud projects (the name above has already been taken and will not work for you, sorry!). It will be referred to later in this codelab as PROJECT_ID.

  1. Next, you'll need to enable billing in Cloud Console in order to use Google Cloud resources.

Running through this codelab shouldn't cost much, if anything at all. Be sure to to follow any instructions in the "Cleaning up" section which advises you how to shut down resources so you don't incur billing beyond this tutorial. New users of Google Cloud are eligible for the $300 USD Free Trial program.

Cloud Shell

You'll use Cloud Shell, a command-line environment running in Google Cloud.

Activate Cloud Shell

  1. From the Cloud Console, click Activate Cloud Shell 4292cbf4971c9786.png.


If you've never started Cloud Shell before, you're presented with an intermediate screen (below the fold) describing what it is. If that's the case, click Continue (and you won't ever see it again). Here's what that one-time screen looks like:


It should only take a few moments to provision and connect to Cloud Shell.


This virtual machine is loaded with all the development tools you need. It offers a persistent 5GB home directory and runs in Google Cloud, greatly enhancing network performance and authentication. Much, if not all, of your work in this codelab can be done with simply a browser or your Chromebook.

Once connected to Cloud Shell, you should see that you are already authenticated and that the project is already set to your project ID.

  1. Run the following command in Cloud Shell to confirm that you are authenticated:
gcloud auth list

Command output

 Credentialed Accounts
*       <my_account>@<>

To set the active account, run:
    $ gcloud config set account `ACCOUNT`
  1. Run the following command in Cloud Shell to confirm that the gcloud command knows about your project:
gcloud config list project

Command output

project = <PROJECT_ID>

If it is not, you can set it with this command:

gcloud config set project <PROJECT_ID>

Command output

Updated property [core/project].

3. Create a new Spring Boot web app

After Cloud Shell launches, you can use the command line to generate a new Spring Boot app with Spring Initializr.

$ curl \
  -d bootVersion=2.3.0.RELEASE \
  -d dependencies=web \
  -d baseDir=gae-standard-example | tar -xzvf -
$ cd gae-standard-example

4. Update Maven pom.xml

There are two ways to deploy a Java server app—either by using Maven App Engine Plugin or Gradle App Engine Plugin, or by deploying the war package directory. You'll use Maven App Engine Plugin to deploy the app.

Add Maven App Engine Plugin

Update pom.xml to include a Google Cloud plugin that simplifies the deployment process. You can use Vim, nano, or Emacs to edit the file.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" ...>

5. Add App Engine descriptor

  1. To deploy the app to App Engine standard environment, you must create a new src/main/appengine/app.yaml descriptor file.
$ mkdir -p src/main/appengine/
$ touch src/main/appengine/app.yaml
  1. Edit the src/main/appengine/app.yaml file and add the following content:


runtime: java11
instance_class: F1

6. Add a controller

Add a new controller that returns "hello world!" in


package com.example.demo;


// Add imports
import org.springframework.web.bind.annotation.*;

public class DemoApplication {
  public static void main(String[] args) {, args);

// Add the controller.
class HelloWorldController {
  public String hello() {
    return "hello world!";

7. Locally run the app

  1. You can start the Spring Boot app with the Spring Boot plugin:
$ ./mvnw -DskipTests spring-boot:run
  1. After the app starts, click Web Preview 396bfd51f55afb5d.pngin the Cloud Shell toolbar and select Preview on port 8080.


A tab in your browser opens and connects to the server that you started.


8. Deploy the app to App Engine

  1. First, initialize the project to be able to run App Engine apps. Also, initialize the project to run in the central region of the US.
$ gcloud app create --region us-central
You are creating an app for project [...].
WARNING: Creating an App Engine application for a project is irreversible and the region
cannot be changed. More information about regions is at
  1. Then, deploy your app to App Engine standard environment by running mvn appengine:deploy.
$ ./mvnw -DskipTests package appengine:deploy
... first time deploy may take a couple of minutes
  1. After the app is deployed, you can visit it by opening http://<project-id> in your web browser or use the following command in Cloud Shell:
$ gcloud app browse
... [It may print out the URL for your app]

9. Congratulations

You learned to write your first App Engine web app!

Learn more