Meta / Contents
Deploy Your Spring Boot App to Google Cloud in One Command
A step-by-step guide to deploying Spring Boot applications to Google App Engine. From zero to production with gcloud app deploy.
Getting a Spring Boot application running on Google Cloud Platform doesn't have to be complicated. Once you've got everything set up, deployment is literally one command: gcloud app deploy. Let me walk you through exactly how to get there.
What We're Building
By the end of this guide, you'll have:
- A Spring Boot application running on App Engine
- Automatic scaling that handles traffic spikes
- A deployment workflow that's just one command
Let's get started!
Prerequisites
Before we dive in, make sure you have these installed and ready:
1. Java Development Kit (JDK 17 or 21)
App Engine supports Java 17 and 21. I recommend JDK 21 for new projects.
# Check your Java version
java -version
If you need to install Java:
macOS (via Homebrew):
brew install openjdk@21
Windows (via Chocolatey):
choco install temurin21
Or download directly from Adoptium.
Linux (via SDKMAN!):
curl -s "https://get.sdkman.io" | bash
sdk install java 21-tem
Alternatively, use your distribution's package manager (e.g., apt install openjdk-21-jdk on Ubuntu/Debian).
2. Google Cloud SDK (gcloud CLI)
This is how you'll deploy and manage your application. Install it from the official documentation.
macOS (via Homebrew):
brew install --cask google-cloud-sdk
Linux/WSL:
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
After installation, initialize the SDK:
gcloud init
This will walk you through signing in and selecting a default project.
3. A Google Cloud Project
If you don't have a project yet, create one:
gcloud projects create my-spring-app --name="My Spring App"
gcloud config set project my-spring-app
You can also create projects in the Cloud Console.
4. Enable App Engine
Enable App Engine for your project and select a region. Choose carefully—you can't change the region later!
gcloud app create --region=us-central
Popular regions include:
us-central- Iowa (good for US users)us-east1- South Carolinaeurope-west- Belgiumasia-northeast1- Tokyo
See all available regions in the App Engine locations documentation.
5. Enable Billing
App Engine requires billing to be enabled, even with the free tier. Visit the Billing page to set up a billing account.
Don't worry—App Engine has a generous free tier that covers most hobby projects.
Prepare Your Spring Boot Application
Build Configuration
Your application needs to be packaged as a JAR with an embedded server. If you're using Spring Boot with Maven or Gradle, you're already set.
Maven (pom.xml):
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Gradle (build.gradle):
plugins {
id 'org.springframework.boot' version '3.3.0'
}
bootJar {
enabled = true
}
The app.yaml Configuration
Create an app.yaml file in src/main/appengine/ (this is the standard location App Engine expects):
runtime: java21
service: default
instance_class: F2
automatic_scaling:
min_instances: 0
max_instances: 10
target_cpu_utilization: 0.65
env_variables:
SPRING_PROFILES_ACTIVE: "gcp"
Let's break this down:
| Setting | What It Does |
|---|---|
runtime: java21 |
Specifies Java 21. Use java17 if needed. |
service: default |
The default service. You can have multiple services for microservices architectures. |
instance_class: F2 |
The instance size. F1 (256MB RAM) is smallest; F4 (1GB RAM) is largest for standard environment. |
min_instances: 0 |
Scales to zero when idle (saves money!). Set to 1+ to avoid cold starts. |
max_instances: 10 |
Maximum instances during traffic spikes. |
target_cpu_utilization: 0.65 |
Spawns new instances when CPU hits 65%. |
See all configuration options in the app.yaml reference.
Configure the Spring Profile
Create an application-gcp.properties (or .yml) file for GCP-specific settings:
# Server configuration
server.port=8080
# Logging for App Engine
logging.level.root=INFO
# Disable Tomcat access logs (App Engine handles this)
server.tomcat.accesslog.enabled=false
Deploy!
Now for the fun part. From your project root, run:
# Build your application first
./mvnw clean package -DskipTests
# Deploy to App Engine
gcloud app deploy src/main/appengine/app.yaml
That's it! The gcloud app deploy command will:
- Upload your JAR file to Cloud Storage
- Build a container image
- Deploy to App Engine
- Route traffic to the new version
The first deployment takes a few minutes. Subsequent deployments are faster.
View Your App
Once deployed, open your app in a browser:
gcloud app browse
Or visit https://YOUR-PROJECT-ID.appspot.com directly.
Useful Commands
Here are the commands you'll use most often:
# Deploy your application
gcloud app deploy src/main/appengine/app.yaml
# View logs in real-time
gcloud app logs tail -s default
# Open app in browser
gcloud app browse
# List all deployed versions
gcloud app versions list
# Check which services are running
gcloud app services list
# View current project
gcloud config get-value project
# Switch projects
gcloud config set project OTHER-PROJECT-ID
Managing Versions and Traffic
Every deployment creates a new version. You can manage traffic between versions:
# List versions
gcloud app versions list
# Send all traffic to a specific version
gcloud app services set-traffic default --splits=VERSION_ID=1
# Split traffic (useful for canary deployments)
gcloud app services set-traffic default --splits=v1=0.9,v2=0.1
Cost Tips
App Engine can be very affordable if you configure it right:
- Set
min_instances: 0— Scales to zero when not in use - Use instance class F1 or F2 — Smaller instances cost less
- Set up billing alerts — Never get surprised by a bill
# Create a budget alert (also do this in Cloud Console)
gcloud billing budgets create \
--billing-account=YOUR-BILLING-ACCOUNT \
--display-name="App Engine Budget" \
--budget-amount=10USD
Visit the Pricing Calculator to estimate costs for your expected traffic.
Troubleshooting
"Permission denied" errors
Make sure you're authenticated and have the right project selected:
gcloud auth login
gcloud config set project YOUR-PROJECT-ID
Application won't start
Check the logs immediately after deployment:
gcloud app logs tail -s default
Common issues:
- Wrong Java version specified in
app.yaml - Missing environment variables
- Port binding issues (always use port 8080)
Cold start latency
If your app takes too long to respond after periods of inactivity, set min_instances: 1 in your app.yaml to keep at least one instance warm.
Next Steps
Once you've got basic deployment working, consider exploring:
- Cloud Build for CI/CD automation
- Secret Manager for secure credential storage
- Cloud Storage for file storage
- Cloud SQL for managed databases
- Custom domains for your own domain name
Wrapping Up
Deploying Spring Boot to Google Cloud Platform really is as simple as one command once you've done the initial setup. The combination of App Engine's automatic scaling, the generous free tier, and the simplicity of gcloud app deploy makes it a fantastic choice for hobby projects and production applications alike.
The hardest part is the first deployment—getting all the prerequisites in place. After that, shipping updates is effortless. I hope this guide helps you get there faster!
–Jeremy