全书目录

第四篇:Spring Boot 完全指南 —— 政务大厅宇宙

第六章:Bean 和依赖注入 —— 谁在大厅里上班

1 分钟 188 字 第 97 / 962 个阅读单元

Spring Boot 应用不是你自己 new 一堆对象到处传,而是交给容器统一调度。

text
Spring 容器 = 人事与调度中心

Controller 需要 Service
Service 需要 Repository
Repository 需要 DataSource

最常见的角色分工:

  • @Controller / @RestController:窗口
  • @Service:审批科
  • @Repository:档案接口
  • @Component:普通岗位
  • @Configuration:制度和装配规则

Spring Boot 现在最推荐的注入方式,是构造器注入