Category: java
Spring Boot project structure
Published on 02 Apr 2026
Explanation
The main class is the entry point
of the Spring Boot application. It contains
the @SpringBootApplication annotation and
starts the embedded
server using SpringApplication.run().
Code:
src/main/java/com/example/demo/
DemoApplication.java
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.
class, args);
}
}
Explanation
The controller layer handles HTTP requests
from clients and returns responses.
It uses annotations
like @RestController and @RequestMapping.
Code:
src/main/java/com/example/demo/controller/
UserController.java
@RestController
@RequestMapping("/users")
public class UserController {
@GetMapping
public String getUsers() {
return "List of users";
}
}
Explanation
The service layer contains business logic.
It acts as a bridge between controller and
repository layers.
Code:
src/main/java/com/example/demo/service/
UserService.java
@Service
public class UserService {
public String getUserServiceMessage() {
return "Business logic executed";
}
}
Explanation
The repository layer interacts with the
database.
It usually extends JpaRepository to
perform CRUD operations.
Code:
src/main/java/com/example/demo/repository/
UserRepository.java
@Repository
public interface UserRepository extends
JpaRepository<User, Long> {
}
Explanation
The resources folder contains configuration
files like
application.properties
static files
template files
required for the application.
Code:
src/main/resources/ ├── application.properties ├── static/ └── templates/