
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a new Spring Boot REST service
/ 30
Configure a secret in Secret Manager
/ 20
Update the app to use the secret greeting
/ 25
Deploy the app to Cloud Run
/ 25
Secrets, like passwords and API keys, are sensitive information that should be stored in a secure, encrypted storage which is access-controlled and auditable. On Google Cloud, you can use Secret Manager, a managed service, to securely store the secrets and control access to individual secrets using IAM.
In Spring Boot, you can use Spring Cloud GCP to easily access these secrets by referring to them as any other Spring properties.
In this lab, you store a secret in Secret Manager, build a Spring Boot app that retrieves and displays the secret, and deploy that app to Cloud Run.
In this lab, you learn how to:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Spring Boot simplifies the creation of self-contained, production-ready Spring applications, ready to run without extensive configuration.
Spring Initializr provides a straightforward path for creating a Spring Boot application. You can use curl to create the application by sending a curl request to the Spring Initializr service.
In this task, you use the command line to generate a new Spring Boot application.
In Cloud Shell, run the following command:
This command downloads a Spring Boot project configuration from Spring Initializr, saves it as a zip file, unpacks it into a subdirectory, and then changes the current directory to the subdirectory.
curl https://start.spring.io/starter.zip
: Fetch a Spring Boot project archive in ZIP format from the Spring Initializr service.-d type=maven-project
: This specifies that the generated project should use Maven as its build system.-d packaging=jar
: This indicates that the application should be packaged as a JAR file.-d bootVersion=3.3.5
: This sets the Spring Boot version to 3.3.5.-d dependencies=web,cloud-gcp
: This defines the project's dependencies. web includes Spring Web support for creating web applications, and cloud-gcp adds the necessary dependencies for interacting with Google Cloud Platform services.-d javaVersion=21
: This specifies that the project should use Java version 21.-d name=HelloSecretManager
: This sets the project name to "HelloSecretManager".-d artifactId=HelloSecretManager
: This sets the Maven artifact ID to "HelloSecretManager".-o ~/hello-secret-manager.zip
: This curl option redirects the downloaded zip file to a local file named hello-secret-manager.zip.In Cloud Shell, to create a new class file, run the following command:
A GET request to "/" should return the string "Hi World!"
To use the correct Java version, run the following command:
To start the REST service, run the following command:
The Maven wrapper command invokes mvnw
in the current directory. Any tests would be skipped. The Maven goal spring-boot:run
compiles the code, and then packages and launches the application.
To access the REST service in the web browser, click Web Preview, and then select Preview on port 8080.
A new tab is opened in the browser, and the application is running. This is the root URL, which displays "Hi World!"
To quit the application, in Cloud Shell, enter CTRL-C
.
To allow progress to be verified, run the following commands to copy the files to the Cloud Storage bucket named
Click Check my progress to verify the objective.
Secret Manager is a secure and convenient storage system for API keys, passwords, certificates, and other sensitive data.
In this task, you enable the Secret Manager API and configure a secret.
To enable the Secret Manager API, in Cloud Shell, run the following command:
To create the secret, run the following command:
This command echoes to STDIN and specifies -
as the data file, which causes STDIN to be used as the source for the secret value.
To list all available secrets, run the following command:
The command lists the secret greeting.
Click Check my progress to verify the objective.
In this task, you update the Java application to retrieve the secret greeting from Secret Manager and display it.
A Secret Manager dependency must be added to the pom.xml
file before the app will be able to access secrets.
In Cloud Shell, click Open Editor.
The Cloud Shell Editor opens.
In the Cloud Shell Editor, navigate to ~/hello-secret-manager/pom.xml
.
In the <dependencies>
node, below the spring-cloud-gcp-starter
dependency, add the Secret Manager starter dependency:
The dependencies
node should now look like this:
This starter simplifies the process of accessing secrets stored in Secret Manager from your Spring Boot application, allowing you to easily retrieve secrets as if they were regular application properties.
Navigate to ~/hello-secret-manager/src/main/resources/application.properties
.
Below the spring.application.name
property, add the following property:
The property configures a Spring PropertySource for accessing Secret Manager secrets.
Navigate to ~/hello-secret-manager/src/main/java/com/example/HelloSecretManager/HelloSecretManagerController.java
.
Insert the following import statement beneath the other imports:
This imports the Value annotation, which can be used to inject a value into a variable.
Change the greeting variable from this:
to this:
The new code retrieves the latest version of the secret named greeting
from Secret Manager and stores it in the variable.
To return to Cloud Shell, click Open Terminal.
To start the REST service, run the following commands:
To access the REST service in the web browser, click Web Preview, and then select Preview on port 8080.
A new tab is opened in the browser, and the application is running. This time the app uses the secret to display "Hello World!"
To quit the application, in Cloud Shell, enter CTRL-C
.
To allow progress to be verified, run the following commands to move the files to the Cloud Storage bucket.
Click Check my progress to verify the objective.
In this task, you deploy the app to Cloud Run. You use a buildpack to automatically create a container for the Java application.
To enable the Cloud Run and Cloud Build APIs, in Cloud Shell, run the following command:
Navigate to ~/hello-secret-manager/src/main/resources/application.properties
.
Below the spring.config.import
property, add the following property:
The property specifies that the environment variable PORT will be used as the port that listens for requests. By default, Cloud Run requests are sent to port 8080, so that is the default used.
A build project descriptor file provides information to Cloud Build for the building of the containeraized app.
To create the build project descriptor file, run the following command:
The project.toml
file in the app root directory specifies that the GOOGLE_RUNTIME_VERSION
environment variable will be set to 21, indicating that Java version 21 should be used to compile the application.
To ensure that only the required permissions are given to the Cloud Run app, a service account is created for the app.
To create a service account named hello-secret-manager-run-sa
, run the following command:
To allow this service account to access secrets in Secret Manager, run the following command:
To change update the secret, run the following command:
When the Cloud Run app is deployed, it should use this new version of the secret.
To deploy the app to Cloud Run, run the following command:
This command deploys the app to Cloud Run with the name hello-secret-manager
.
--region
: The region for deployment.--allow-unauthenticated
: Makes your Cloud Run service publicly accessible without requiring any authentication. This flag should not be used for sensitive applications.--service-account
: Specifies the service account, and therefore the permissions allowed by the app.--source
: Specifies the source root directory. Specifying the source directory instead of a container indicates that Cloud Build should build the container.After a few minutes, the deployment completes.
To get the application URL, run the following command:
Click the link created by the previous command.
A new tab opens and the message "Greetings World!" is displayed.
Click Check my progress to verify the objective.
In this lab, you stored a secret in Secret Manager, built a Spring Boot app that retrieves and displays the secret, and deployed that app to Cloud Run.
Check out the following resource to learn more about using Spring Boot on Google Cloud:
Manual Last Updated July 29, 2025
Lab Last Tested July 29, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one