...
/Basic Concepts and Components of a Project
Basic Concepts and Components of a Project
Understand the basic concepts of a project, such as autoconfiguration and component scanning.
We'll cover the following...
The initial code we’ve built is given below. Let’s explore some of the other files provided to us:
<?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
Java application class
In addition to the build file we just looked at, the Spring Initializr provides the following application file:
@SpringBootApplicationpublic class HackingWithSpringBootApplication {public static void main(String[] args) {SpringApplication.run(HackingWithSpringBootApplication.class, args);}}
This class contains:
-
@SpringBootApplication: A composite annotation that introduces autoconfiguration and component scanning. -
main(String[] args): A runnable function to launch our application. -
SpringApplication.run(HackingSpringBootApplication.class, args): A Spring Boot hook to register this class as the launch point ...
Ask