AI Hints
Home›Spring Boot Tutorial›What You Need, Spring Initializr and The Project Structure
Spring Boot · Lesson 6 of 120

The Project Structure

What is inside.

⏱ 2 min read▶ Video at 6:49🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Let's open the project, and look at each file. There are only a few, and each has a clear job.

  • Open the project
  • Only a few files
  • Each has a job

The folders

Pom dot xml describes the project for Maven. Mvnw is the Maven wrapper. Our Java code lives under source, main, java, inside the package folders. Settings live in source, main, resources. And tests live in source, test, java.

bookshoptext
bookshop/
├── pom.xml
├── mvnw
├── src/main/java/com/example/bookshop/
│   └── BookshopApplication.java
├── src/main/resources/
│   └── application.properties
└── src/test/java/com/example/bookshop/
    └── BookshopApplicationTests.java

pom.xml

The parent section makes this a Spring Boot project, version four point two. Group id and artifact id name our project. Java version is seventeen. And under dependencies, the web starter brings everything we need for web endpoints. A starter is a bundle of libraries, that are known to work well together.

pom.xmlxml
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.2.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>bookshop</artifactId>
<properties>
    <java.version>17</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webmvc</artifactId>
    </dependency>
</dependencies>

application.properties

Application dot properties holds settings, as key equals value lines. Spring application name names our app. Server port is the port, and eight zero eight zero is the default. Here's a small controller that reads the name setting. Run it. The app reads bookshop, from the properties file.

application.propertiesini
spring.application.name=bookshop
server.port=8080
Output
This app is called bookshop
Also uses InfoController.java
@RestController
public class InfoController {

    @Value("${spring.application.name}")
    private String name;

    @GetMapping("/info")
    public String info() {
        return "This app is called " + name;
    }
}
Also uses _curl.sh
curl localhost:8080/info

Summary

Pom dot xml describes the project, code lives in source main java, and settings in application dot properties. Next, the main class.

Key takeaways
  • pom.xml
  • src/main/java
  • application.properties
Next up: The Main Class — where it all starts