diff --git a/README.md b/README.md index 9dd6a0f15954815741861453b006401b93a89450..e78e9d32950bc09091c310eb2c8fbfed5a1ab802 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,165 @@ -# Spring Framework [![Build Status](https://github.com/spring-projects/spring-framework/actions/workflows/build-and-deploy-snapshot.yml/badge.svg?branch=main)](https://github.com/spring-projects/spring-framework/actions/workflows/build-and-deploy-snapshot.yml?query=branch%3Amain) [![Revved up by Develocity](https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.spring.io/scans?search.rootProjectNames=spring) +# Spring Framework 中文文档 + +Spring Framework 是 Spring 项目家族的基础,提供了构建企业级 Java 应用所需的各种功能。它支持依赖注入、面向切面编程(AOP)、数据访问、事务管理、消息传递、Web 开发等核心功能。 + +## 项目结构概览 + +本项目包含多个模块,主要模块如下: + +- **spring-aop**: 提供面向切面编程(AOP)的支持。 +- **spring-beans**: 提供 Bean 的创建、配置和管理。 +- **spring-context**: 提供应用上下文(ApplicationContext)支持。 +- **spring-core**: 提供 Spring 框架的核心工具类。 +- **spring-expression**: 提供 Spring 表达式语言(SpEL)支持。 +- **spring-jdbc**: 提供对 JDBC 的简化支持。 +- **spring-orm**: 提供对 Hibernate、JPA 等 ORM 框架的集成。 +- **spring-oxm**: 提供对象与 XML 映射支持。 +- **spring-test**: 提供对单元测试和集成测试的支持。 +- **spring-tx**: 提供声明式事务管理。 +- **spring-web**: 提供基础 Web 支持。 +- **spring-webmvc**: 提供基于 MVC 架构的 Web 框架。 +- **spring-webflux**: 提供响应式 Web 开发支持。 +- **framework-docs**: 提供 Spring Framework 的文档和示例代码。 + +## 主要功能 + +### 1. 控制反转(IoC)与依赖注入(DI) + +Spring 提供了强大的依赖注入机制,通过 `@Autowired`、`@Component`、`@Service`、`@Repository` **实现组件自动扫描与装配**。 + +```java +@Service +public class MyService { + private final MyRepository repository; -This is the home of the Spring Framework: the foundation for all [Spring projects](https://spring.io/projects). Collectively the Spring Framework and the family of Spring projects are often referred to simply as "Spring". + @Autowired + public MyService(MyRepository repository) { + this.repository = repository; + } +} +``` -Spring provides everything required beyond the Java programming language for creating enterprise applications for a wide range of scenarios and architectures. Please read the [Overview](https://docs.spring.io/spring-framework/reference/overview.html) section of the reference documentation for a more complete introduction. +### 2. 面向切面编程(AOP) -## Code of Conduct +Spring AOP 支持将横切关注点(如日志、安全、事务)与业务逻辑分离。 -This project is governed by the [Spring Code of Conduct](https://github.com/spring-projects/spring-framework/?tab=coc-ov-file#contributor-code-of-conduct). By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to spring-code-of-conduct@spring.io. +```java +@Aspect +@Component +public class LoggingAspect { + @Before("execution(* com.example.service.*.*(..))") + public void logBefore(JoinPoint joinPoint) { + System.out.println("Method called: " + joinPoint.getSignature().getName()); + } +} +``` -## Access to Binaries +### 3. 数据访问与事务管理 -For access to artifacts or a distribution zip, see the [Spring Framework Artifacts](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Artifacts) wiki page. +Spring 提供了统一的数据访问层抽象,支持 JDBC、Hibernate、JPA 等,并通过 `@Transactional` 实现声明式事务管理。 -## Documentation +```java +@Repository +public class MyRepository { + @Transactional + public void saveData(Data data) { + // 数据库操作 + } +} +``` -The Spring Framework maintains reference documentation ([published](https://docs.spring.io/spring-framework/reference/) and [source](framework-docs/modules/ROOT)), GitHub [wiki pages](https://github.com/spring-projects/spring-framework/wiki), and an -[API reference](https://docs.spring.io/spring-framework/docs/current/javadoc-api/). There are also [guides and tutorials](https://spring.io/guides) across Spring projects. +### 4. Web 开发支持 -## Micro-Benchmarks +Spring MVC 提供了基于注解的 Web 开发支持,支持 RESTful API、视图解析、异常处理等。 -See the [Micro-Benchmarks](https://github.com/spring-projects/spring-framework/wiki/Micro-Benchmarks) wiki page. +```java +@RestController +@RequestMapping("/api") +public class MyController { + @GetMapping("/hello") + public String sayHello() { + return "Hello, Spring!"; + } +} +``` -## Build from Source +### 5. 响应式编程(WebFlux) -See the [Build from Source](https://github.com/spring-projects/spring-framework/wiki/Build-from-Source) wiki page and the [CONTRIBUTING.md](CONTRIBUTING.md) file. +Spring WebFlux 提供了非阻塞式的 Web 开发支持,适用于高并发场景。 -## Continuous Integration Builds +```java +@RestController +public class ReactiveController { + @GetMapping("/flux") + public Flux getFlux() { + return Flux.just("Hello", "Spring", "WebFlux"); + } +} +``` -Information regarding CI builds can be found in the [Spring Framework Concourse pipeline](ci/README.adoc) documentation. +### 6. 测试支持 -## Stay in Touch +Spring 提供了对 JUnit、Mockito 等测试框架的集成,支持单元测试和集成测试。 -Follow [@SpringCentral](https://twitter.com/springcentral), [@SpringFramework](https://twitter.com/springframework), and its [team members](https://twitter.com/springframework/lists/team/members) on 𝕏. In-depth articles can be found at [The Spring Blog](https://spring.io/blog/), and releases are announced via our [releases feed](https://spring.io/blog/category/releases). +```java +@SpringBootTest +public class MyServiceTest { + @Autowired + private MyService myService; -## License + @Test + void testService() { + assertNotNull(myService); + } +} +``` -The Spring Framework is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). +## 构建与部署 + +本项目使用 Gradle 构建工具,支持多模块构建、依赖管理、测试运行等。 + +### 构建命令 + +```bash +./gradlew build +``` + +### 运行测试 + +```bash +./gradlew test +``` + +### 发布到 Maven 仓库 + +```bash +./gradlew publish +``` + +## 开发环境配置 + +### 导入到 IntelliJ IDEA + +1. 打开 IntelliJ IDEA。 +2. 选择 "Open" 并选择项目根目录。 +3. IDEA 会自动识别 Gradle 项目并导入。 + +### 导入到 Eclipse + +1. 安装 Spring Tool Suite(STS)插件。 +2. 选择 "Import Existing Project"。 +3. 选择项目根目录并导入。 + +## 文档与资源 + +- [Spring Framework 官方文档](https://docs.spring.io/spring-framework/reference/) +- [Spring Boot 文档](https://docs.spring.io/spring-boot/docs/current/reference/html/) +- [Spring 项目主页](https://spring.io/projects) + +## 贡献指南 + +请参考 [CONTRIBUTING.md](CONTRIBUTING.md) 获取如何贡献代码、提交 Issue 和 Pull Request 的详细说明。 + +## 许可证 + +本项目采用 [Apache License 2.0](LICENSE.txt) 开源协议。 \ No newline at end of file