In this tutorial, we will learn how to deploy a spring boot MVC application on AWS using the Elastic beanstalk service.
The YouTube video version of this tutorial available at Deploy Spring Boot MVC Application on AWS | Elastic Beanstalk ( YouTube Video)
With Elastic Beanstalk, you can quickly deploy and manage applications in the AWS Cloud without having to learn about the infrastructure that runs those applications. Elastic Beanstalk reduces management complexity without restricting choice or control. You simply upload your application, and Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring.
To understand more about this tutorial, I have created a YouTube video on the same topic so I highly recommend you to watch the YouTube video. (YouTube video present at end of this tutorial)
Development process:
1. Create Spring Boot Application
2. Build a simple Thymeleaf hello world page
3. Package the JAR file using Maven
4. Create a new application in Elastic Beanstalk
5. Upload the JAR file to Elastic Beanstalk
#javaguides #springboot @aws
1. Create Spring Boot Application
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<packaging>war</packaging>
<groupId>net.javaguides</groupId>
<artifactId>springboot-web-app-aws-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-web-app-aws-example</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>springboot-web-app-aws-example</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2. Build a simple Thymeleaf hello world page
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Spring boot Thymeleaf App deployment on AWS</title>
</head>
<body>
<h1 th:text = "${message}"></h1>
</body>
</html>
package net.javaguides.springboot;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloWorldController {
@GetMapping("/hello")
public String hello(Model model) {
model.addAttribute("message", "Deploying Spring MVC App on AWS");
return "helloworld";
}
}
3. Package the JAR file using Maven
mvn clean install
4. Create a new application in Elastic Beanstalk
1. Login to AWS console5. Upload the JAR file to Elastic Beanstalk
How to change the post?
server.port=5000
Comments
Post a Comment
Leave Comment