Deploy a Java application using Spring Boot on Google Cloud

Google Cloud offers many other features that you can configure, such as databases, storage, monitoring, and more.

Use Google App Engine, which is a serverless platform that makes it easy to deploy and automatically scale applications. Next, I’ll show …


This content originally appeared on DEV Community and was authored by Marant7

Google Cloud offers many other features that you can configure, such as databases, storage, monitoring, and more.

Use Google App Engine, which is a serverless platform that makes it easy to deploy and automatically scale applications. Next, I'll show you how to do it.

Step 1: Set up your environment

  1. Install Google Cloud SDK: If you don't have it installed yet, follow the instructions here.

  2. Initialize Google Cloud SDK: Set up your Google Cloud environment by running:

gcloud init

  1. Install the App Engine plugin:

gcloud components install app-engine-java

Step 2: Create a Spring Boot Application

  1. Create a Spring Boot project:

o Project: Maven Project
o Language: Java
o Spring Boot: 2.5.x
o Project Metadata: Enter the name of your group, artifact, and other details.
o Dependencies: Add Spring Web.

Then, build the project and download the ZIP file. Unzip the file on your machine.

  1. Create the Spring Boot application: Open your project in your favorite IDE

  2. Create a simple controller: In the directory

src/main/java/com/example/demo (adjust according to your structure), create a file called HelloController.java with the following content:

package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@GetMapping("/")
public String hello() {
    return "Hello, World!";
}

}

  1. Make sure the application runs: Run your application with the mvn spring-boot:run command and verify that you can access http://localhost:8080 and see the "Hello, World!" message

Step 3: Prepare your app for App Engine

  1. Create the app.yaml file: In the root directory of your project, create a file called app.yaml with the following content: runtime: java11 instance_class: F1

This file tells App Engine to use the Java 11 runtime.

  1. Package your application: Build your application to generate the executable JAR file. Use the Java 11 runtime environment.

mvn clean package

Step 4: Deploy the app to Google App Engine

1.Deploy the application:

gcloud app deploy target/demo-0.0.1-SNAPSHOT.jar

Follow the instructions and confirm the deployment when prompted.

2.Abrir la aplicación:

gcloud app browse

Tu aplicación Spring Boot ahora debería estar desplegada en Google App Engine. Puedes actualizar el código y redeployar usando el mismo comando gcloud app deploy.


This content originally appeared on DEV Community and was authored by Marant7


Print Share Comment Cite Upload Translate Updates
APA

Marant7 | Sciencx (2024-07-04T23:15:33+00:00) Deploy a Java application using Spring Boot on Google Cloud. Retrieved from https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/

MLA
" » Deploy a Java application using Spring Boot on Google Cloud." Marant7 | Sciencx - Thursday July 4, 2024, https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/
HARVARD
Marant7 | Sciencx Thursday July 4, 2024 » Deploy a Java application using Spring Boot on Google Cloud., viewed ,<https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/>
VANCOUVER
Marant7 | Sciencx - » Deploy a Java application using Spring Boot on Google Cloud. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/
CHICAGO
" » Deploy a Java application using Spring Boot on Google Cloud." Marant7 | Sciencx - Accessed . https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/
IEEE
" » Deploy a Java application using Spring Boot on Google Cloud." Marant7 | Sciencx [Online]. Available: https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/. [Accessed: ]
rf:citation
» Deploy a Java application using Spring Boot on Google Cloud | Marant7 | Sciencx | https://www.scien.cx/2024/07/04/deploy-a-java-application-using-spring-boot-on-google-cloud/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.