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
- BeanFactory vs ApplicationContext — container thực sự là gì:
singletonObjectsmap, composition + delegation. - refresh() — 12 bước — method biến config thành runtime container, 3 giai đoạn.
- BeanDefinition & BeanFactoryPostProcessor — metadata bean và can thiệp trước khi instantiate.
- Environment & PropertySource — externalized config, thứ tự ưu tiên, relax binding.
- Resource & @SpringBootApplication — nạp resource thống nhất + app bootstrap (3 annotation, không magic).
- 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
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