1
---
2
name: spring-boot-application
3
description: >
4
Build enterprise Spring Boot applications with annotations, dependency
5
injection, data persistence, REST controllers, and security. Use when
6
developing Spring applications, managing beans, implementing services, and
7
configuring Spring Boot projects.
8
---
9
10
# Spring Boot Application
11
12
## Table of Contents
13
14
- [Overview](#overview)
15
- [When to Use](#when-to-use)
16
- [Quick Start](#quick-start)
17
- [Reference Guides](#reference-guides)
18
- [Best Practices](#best-practices)
19
20
## Overview
21
22
Develop production-ready Spring Boot applications with proper annotation-based configuration, dependency injection, REST controllers, JPA data persistence, service layers, and security implementation following Spring conventions.
23
24
## When to Use
25
26
- Building Spring Boot REST APIs
27
- Implementing service-oriented architectures
28
- Configuring data persistence with JPA
29
- Managing dependency injection
30
- Implementing Spring Security
31
- Building microservices with Spring Boot
32
33
## Quick Start
34
35
Minimal working example:
36
37
```xml
38
<!-- pom.xml -->
39
<project>
40
<modelVersion>4.0.0</modelVersion>
41
<groupId>com.example</groupId>
42
<artifactId>api-service</artifactId>
43
<version>1.0.0</version>
44
45
<parent>
46
<groupId>org.springframework.boot</groupId>
47
<artifactId>spring-boot-starter-parent</artifactId>
48
<version>3.1.0</version>
49
</parent>
50
51
<dependencies>
52
<dependency>
53
<groupId>org.springframework.boot</groupId>
54
<artifactId>spring-boot-starter-web</artifactId>
55
</dependency>
56
<dependency>
57
<groupId>org.springframework.boot</groupId>
58
<artifactId>spring-boot-starter-data-jpa</artifactId>
59
</dependency>
60
<dependency>
61
<groupId>org.springframework.boot</groupId>
62
<artifactId>spring-boot-starter-security</artifactId>
63
// ... (see reference guides for full implementation)
64
```
65
66
## Reference Guides
67
68
Detailed implementations in the `references/` directory:
69
70
| Guide | Contents |
71
|---|---|
72
| [Spring Boot Project Setup](references/spring-boot-project-setup.md) | Spring Boot Project Setup |
73
| [Entity Models with JPA Annotations](references/entity-models-with-jpa-annotations.md) | Entity Models with JPA Annotations |
74
| [Repository Layer with Spring Data JPA](references/repository-layer-with-spring-data-jpa.md) | Repository Layer with Spring Data JPA |
75
| [Service Layer with Business Logic](references/service-layer-with-business-logic.md) | Service Layer with Business Logic |
76
| [REST Controllers with Request/Response Handling](references/rest-controllers-with-requestresponse-handling.md) | REST Controllers with Request/Response Handling |
77
| [Spring Security Configuration](references/spring-security-configuration.md) | Spring Security Configuration |
78
| [Application Configuration](references/application-configuration.md) | Application Configuration |
79
80
## Best Practices
81
82
### ✅ DO
83
84
- Use dependency injection for loose coupling
85
- Implement service layer for business logic
86
- Use repositories for data access
87
- Leverage Spring Security for authentication
88
- Use @Transactional for transaction management
89
- Validate input in controllers
90
- Return appropriate HTTP status codes
91
- Use DTOs for request/response mapping
92
- Implement proper exception handling
93
- Use Spring's @Async for async operations
94
95
### ❌ DON'T
96
97
- Put business logic in controllers
98
- Access database directly in controllers
99
- Store secrets in configuration files
100
- Use eager loading for large relationships
101
- Ignore transaction boundaries
102
- Return database entities in API responses
103
- Implement authentication in controllers
104
- Use raw SQL without parameterized queries
105
- Forget to validate user input
106