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
Install Google Cloud SDK: If you don't have it installed yet, follow the instructions here.
Initialize Google Cloud SDK: Set up your Google Cloud environment by running:
gcloud init
- Install the App Engine plugin:
gcloud components install app-engine-java
Step 2: Create a Spring Boot Application
- 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.
Create the Spring Boot application: Open your project in your favorite IDE
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!";
}
}
- 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
- 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.
- 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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.