Spring Core & Boot/Container Internals — tổng quan
7/41
Bài 7 / 41~4 phútContainer InternalsMiễn phí lượt xem

Container Internals — tổng quan

Mổ bên trong IoC container Spring qua 5 bài atomic: hai interface, refresh() 12 bước, BeanDefinition + BFPP, Environment, Resource + @SpringBootApplication.

Module trước trả lời IoC/DI là gì. Module này trả lời câu hỏi sâu hơn: cái container thực thi IoC đó bên trong hoạt động ra sao? Mỗi bài bóc một mảnh của container, đẩy tới mức data structure và source thật — để khi đọc stack trace Spring lúc startup, bạn biết chính xác lỗi xảy ra ở đâu.

flowchart LR
  A["01 BeanFactory<br/>vs ApplicationContext"] --> B["02 refresh()<br/>12 buoc"]
  B --> C["03 BeanDefinition<br/>+ BFPP"]
  C --> D["04 Environment<br/>+ PropertySource"]
  D --> E["05 Resource<br/>+ SpringBootApplication"]
  E --> F["06 Mini-challenge<br/>tu build mini-IoC"]

Các bài trong module

  1. BeanFactory vs ApplicationContext — container thực sự là gì: singletonObjects map, composition + delegation.
  2. refresh() — 12 bước — method biến config thành runtime container, 3 giai đoạn.
  3. BeanDefinition & BeanFactoryPostProcessor — metadata bean và can thiệp trước khi instantiate.
  4. Environment & PropertySource — externalized config, thứ tự ưu tiên, relax binding.
  5. Resource & @SpringBootApplication — nạp resource thống nhất + app bootstrap (3 annotation, không magic).
  6. Mini-challenge — tự build mini IoC container ~50 dòng để chứng minh đã hiểu.

Learning outcomes

  • Explain BeanFactory vs ApplicationContext và data structure thật (singletonObjects, beanDefinitionMap)
  • Trace refresh() 12 bước qua 3 giai đoạn biến config thành runtime container
  • Compare BeanFactoryPostProcessor (metadata) vs BeanPostProcessor (instance) và BeanDefinition
  • Implement externalized config với Environment + PropertySource đúng thứ tự ưu tiên
  • Diagnose lỗi container (bean không scan, sai thứ tự property) qua Resource + @SpringBootApplication

Yêu cầu trước

Hoàn thành module Nhập môn & IoC/DI.

Bài này có giúp bạn hiểu bản chất không?

Hỏi đáp về bài này

Chưa có câu hỏi

Đặt câu hỏi

Có gì chưa rõ trong bài? Đặt câu hỏi đầu tiên — câu trả lời từ cộng đồng giúp bạn (và người sau).

Đặt câu hỏi đầu tiên