Provides comprehensive guidance for Spring Boot development including project creation, auto-configuration, dependency injection, web development, data access, security, testing, and deployment. Use when the user asks about Spring Boot, needs to create Spring Boot applications, configure Spring Boot, or implement Spring Boot features.
View on GitHubpartme-ai/full-stack-skills
development-skills-utils
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/partme-ai/full-stack-skills/blob/main/skills/spring-boot/SKILL.md -a claude-code --skill spring-bootInstallation paths:
.claude/skills/spring-boot/# Spring Boot 开发指南
## 概述
Spring Boot 是一个基于 Spring 框架的快速开发框架,提供了自动配置、起步依赖等特性,简化了 Spring 应用的开发。
## 核心特性
### 1. 项目创建
**使用 Spring Initializr**:
访问 https://start.spring.io/ 或使用 IDE 插件创建项目。
**使用 CLI**:
```bash
# 安装 Spring Boot CLI
brew install spring-boot
# 创建项目
spring init --dependencies=web,data-jpa,postgresql my-project
```
**Maven 项目结构**:
```
my-project/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/
│ │ │ └── MyApplication.java
│ │ └── resources/
│ │ ├── application.properties
│ │ └── application.yml
│ └── test/
├── pom.xml
└── README.md
```
### 2. 自动配置
Spring Boot 通过自动配置简化了配置工作。
**application.yml**:
```yaml
spring:
application:
name: my-app
datasource:
url: jdbc:postgresql://localhost:5432/mydb
username: postgres
password: password
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
server:
port: 8080
```
**application.properties**:
```properties
spring.application.name=my-app
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
server.port=8080
```
### 3. 依赖注入
**使用 @Component**:
```java
@Component
public class UserService {
public String getUserName(Long id) {
return "User " + id;
}
}
```
**使用 @Service**:
```java
@Service
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public User findById(Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new UserNotFoundException(id));
}
}
```
**使用 @Repository**:
```java
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByE