Getting Started with Our Project
Understand the initial code of our empty project in detail.
We'll cover the following...
The initial code we’ve built is given below. Let’s take a look at the basic structure of a Spring 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.5.6</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.greglturnquist</groupId> <artifactId>hackingspringboot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>hackingspringboot</name> <description>Demo project for Hacking with Spring Boot</description> <properties> <java.version>11</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-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.fizzed</groupId> <artifactId>fizzed-watcher-maven-plugin</artifactId> <version>1.0.6</version> <configuration> <watches> <watch> <directory>src/main</directory> <exclude>*.css</exclude> <exclude>*.js</exclude> <exclude>*.svg</exclude> </watch> </watches> <goals> <goal>compile</goal> <goal>process-classes</goal> </goals> </configuration> </plugin> </plugins> </build> </project>
An empty Spring Boot project
Description of the files
The following is a description of the individual files that are important in a Spring Boot project:
- The Maven project file,
pom.xml
, is the most important file that’s configured with the selected dependencies and thespringboot-maven-plugin
. It’s used to generate the standalone executable JAR file. - The
HackingspringbootApplication.java
file is the main application file of our project. - The
application.properties
file is the properties file that allows us to customize the different parts of