Book Image

Full Stack Development with Spring Boot 3 and React - Fourth Edition

By : Juha Hinkula
5 (1)
Book Image

Full Stack Development with Spring Boot 3 and React - Fourth Edition

5 (1)
By: Juha Hinkula

Overview of this book

If you’re an existing Java developer who wants to go full stack or pick up another frontend framework, this book is your concise introduction to React. In this three-part build-along, you’ll create a robust Spring Boot backend, a React frontend, and then deploy them together. This new edition is updated to Spring Boot 3 and includes expanded content on security and testing. For the first time ever, it also covers React development with the in-demand TypeScript. You’ll explore the elements that go into creating a REST API and testing, securing, and deploying your applications. You’ll learn about custom Hooks, third-party components, and MUI. By the end of this book, you'll be able to build a full stack application using the latest tools and modern best practices.
Table of Contents (23 chapters)
1
Part I: Backend Programming with Spring Boot
8
Part II: Frontend Programming with React
14
Part III: Full Stack Development
21
Other Books You May Enjoy
22
Index

Understanding Gradle

Gradle is a build automation tool that makes the software development process simpler and also unifies the development process. It manages our project dependencies and handles the build process.

IMPORTANT NOTE

You can also use another project management tool called Maven with Spring Boot, but we will focus on using Gradle in this book because it’s faster and more flexible than Maven.

We don’t need to perform any installations to use Gradle in our Spring Boot project since we are utilizing the Gradle wrapper within our project.

The Gradle configuration is done in the project’s build.gradle file. The file can be customized to fit the specific needs of the project and can be used to automate tasks such as building, testing, and deploying the software. The build.gradle file is an important part of the Gradle build system and is used to configure and manage the build process for a software project. The build.gradle file typically includes information about the project’s dependencies, like external libraries and frameworks that are needed for the project to compile. You can use either the Kotlin or Groovy programming languages to write build.gradle files. In this book, we are using Groovy. The following is one example of a Spring Boot project’s build.gradle file:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.0'
    id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.packt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
    mavenCentral()
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-
    test'
}
tasks.named('test') {
    useJUnitPlatform()
}

The build.gradle file typically contains the following parts:

  • Plugins: The plugins block defines the Gradle plugins that are used in the project. In this block, we can define the version of Spring Boot.
  • Repositories: The repositories block defines the dependency repositories that are used to resolve dependencies. We are using the Maven Central repository, from which Gradle pulls the dependencies.
  • Dependencies: The dependencies block specifies the dependencies that are used in the project.
  • Tasks: The tasks block defines the tasks that are part of the build process, such as testing.

Gradle is often used from the command line, but we are using the Gradle wrapper and Eclipse, which handles all the Gradle operations we need. The wrapper is a script that invokes a declared version of Gradle, and it standardizes your project to a given Gradle version. Therefore, we are not focusing on Gradle command-line usage here. The most important thing is to understand the structure of the build.gradle file and how to add new dependencies to it. We will learn how to add dependencies using Spring Initializr in the next section. Later in this book, we will also add new dependencies manually to the build.gradle file.

In the next section, we will create our first Spring Boot project and see how we can run it using the Eclipse IDE.