Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Full Stack Development with Spring Boot and React - Third Edition

You're reading from  Full Stack Development with Spring Boot and React - Third Edition

Product type Book
Published in Apr 2022
Publisher Packt
ISBN-13 9781801816786
Pages 378 pages
Edition 3rd Edition
Languages
Author (1):
Juha Hinkula Juha Hinkula
Profile icon Juha Hinkula

Table of Contents (22) Chapters

Preface 1. Part 1: Backend Programming with Spring Boot
2. Chapter 1: Setting Up the Environment and Tools – Backend 3. Chapter 2: Understanding Dependency Injection 4. Chapter 3: Using JPA to Create and Access a Database 5. Chapter 4: Creating a RESTful Web Service with Spring Boot 6. Chapter 5: Securing and Testing Your Backend 7. Part 2: Frontend Programming with React
8. Chapter 6: Setting Up the Environment and Tools – Frontend 9. Chapter 7: Getting Started with React 10. Chapter 8: Consuming the REST API with React 11. Chapter 9: Useful Third-Party Components for React 12. Part 3: Full Stack Development
13. Chapter 10: Setting up the Frontend for Our Spring Boot RESTful Web Service 14. Chapter 11: Adding CRUD Functionalities 15. Chapter 12: Styling the Frontend with React MUI 16. Chapter 13: Testing Your Frontend 17. Chapter 14: Securing Your Application 18. Chapter 15: Deploying Your Application 19. Chapter 16: Best Practices 20. Assessments 21. Other Books You May Enjoy

Chapter 15: Deploying Your Application

This chapter will explain how to deploy your backend and frontend to a server. Successful deployment is a key part of the software development process, and it is important to learn how a modern deployment process works. There are a variety of cloud servers or PaaS (short for Platform-as-a-Service) providers available, such as Amazon Web Services (AWS), DigitalOcean, and Microsoft Azure. In this book, we are using Heroku and AWS, which support multiple programming languages that are used in web development. We will also show you how to use Docker containers in deployment.

In this chapter, we will cover the following topics:

  • Deploying the backend
  • Deploying the frontend
  • Using Docker containers

Technical requirements

The Spring Boot application that we created in Chapter 5, Securing and Testing Your Backend is required (it is available on GitHub at https://github.com/PacktPublishing/Full-Stack-Development-with-Spring-Boot-and-React/tree/main/Chapter05), as is the React app that we used in Chapter 13, Testing Your Frontend (it is available on GitHub at https://github.com/PacktPublishing/Full-Stack-Development-with-Spring-Boot-and-React/tree/main/Chapter13).

Docker installation is necessary, and the following GitHub link will also be required: https://github.com/PacktPublishing/Full-Stack-Development-with-Spring-Boot-and-React/tree/main/Chapter15.

Deploying the backend

If you are going to use your own server, the easiest way to deploy the Spring Boot application is to use an executable Java ARchive (JAR) file. If you use Maven, an executable JAR file can be created using the Spring Boot Maven plugin and adding the following lines of code to your pom.xml file:

 <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

Next, we have to build our project using the mvn clean install command. You can run a custom maven command in the Eclipse integrated development environment (IDE) by right-clicking Project in the project explorer, selecting Run as | Maven Build…, and typing clean install in the Goals...

Deploying the frontend

You can deploy your frontend to Heroku as well, but we will now use AWS Amplify for the deployment.

First, we have to change our REST API URL. Open your frontend project with Visual Studio Code (VS Code) and open the constants.js file in the editor. Change the SERVER_URL constant to match your backend's URL, as follows, and save the changes:

export const SERVER_URL = 'https://carbackend.herokuapp.com/';

Then, push your code to GitHub and follow the next steps:

  1. Log in to the Amplify console (https://console.aws.amazon.com/amplify/home).
  2. Press the Get started button under Amplify Hosting, as illustrated in the following screenshot:

Figure 15.14 – Amplify Hosting

  1. Select GitHub and press the Continue button, as illustrated in the following screenshot. First, you have to link your GitHub account to Amplify:

Figure 15.15 – GitHub repository

  1. Next, select...

Using Docker containers

Docker is a container platform that makes software development, deployment, and shipping easier. Containers are lightweight and executable software packages that include everything that is needed to run software. In this section, we are creating a container from our Spring Boot backend, as follows:

  1. Install Docker on your workstation. You can find the installation packages at https://www.docker.com/get-docker. There are installation packages for multiple platforms, and if you have a Windows operating system, you can go through the installation wizard using the default settings. After the installation, you can check the current version by typing the following command in the terminal:
    heroku --version
  2. First, we have to create an executable JAR file from our Spring Boot application, just as we did at the beginning of this chapter. Right-click your project in the project explorer and select Run as | Maven build... from the menu. Select your project in...

Summary

In this chapter, you learned how to deploy the Spring Boot application. We went through the different deployment options for the Spring Boot application and deployed the application to Heroku. Next, we deployed our React frontend using AWS Amplify. Finally, we used Docker to create containers from our Spring Boot application and the MariaDB database.

In the next chapter, we will cover some more technologies and best practices that you should explore.

Questions

  1. How should you create a Spring Boot executable JAR file?
  2. How should you deploy a Spring Boot application to Heroku?
  3. How should you deploy a React app using AWS Amplify?
  4. What is Docker?
  5. How should you create a Spring Boot application container?
  6. How should you create a MariaDB container?

Further reading

Packt Publishing has other great resources available for learning about React, Spring Boot, and Docker. A couple of them are listed here:

lock icon The rest of the chapter is locked
You have been reading a chapter from
Full Stack Development with Spring Boot and React - Third Edition
Published in: Apr 2022 Publisher: Packt ISBN-13: 9781801816786
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}