Nội dung
Danh sách bài học
- 01~4 phút
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.
- 02~12 phút
BeanFactory vs ApplicationContext — container thực sự là cái gì bên dưới
Container Spring không phải hộp đen. Bài này bóc đúng MỘT thứ: hai interface BeanFactory và ApplicationContext khác nhau ra sao, và bên dưới chúng được implement bằng data structure nào — singletonObjects map, beanDefinitionMap, và cơ chế delegation khiến ApplicationContext 'là' một BeanFactory.
- 03~12 phút
refresh() — 12 bước biến config thành runtime container
refresh() là method quan trọng nhất của ApplicationContext. Bài này đi sâu 12 bước trong AbstractApplicationContext.refresh(): từ load BeanDefinition đến eager instantiate singleton, chia 3 giai đoạn rõ ràng. Hiểu cơ chế này là chìa khoá debug mọi startup error — BeanCreationException, NoSuchBeanDefinitionException, BeanCurrentlyInCreationException — vì mỗi loại lỗi ứng với đúng một bước.
- 04~12 phút
BeanDefinition & BeanFactoryPostProcessor — metadata bean và pha can thiệp trước instantiate
BeanDefinition là bản mô tả metadata của bean (class, scope, dependencies) — chưa phải object thật. BeanFactoryPostProcessor (BFPP) có thể chỉnh sửa metadata này trước khi container instantiate bất kỳ bean nào. Bài này đào sâu hai khái niệm đó, phân biệt BFPP vs BPP, và giải thích vì sao tách pha metadata khỏi instance là nền móng của autoconfig Spring.
- 05~12 phút
Environment & PropertySource — externalized config và thứ tự ưu tiên
Environment là 1 trong 4 capability của ApplicationContext: quản lý property (từ command line, env var, application.properties, ...) và profile (dev/prod/test). Bài này bóc cơ chế PropertySource ordering, relax binding, @Value/${...}/SpEL — giải thích vì sao command line override mọi thứ và vì sao env var tồn tại song song system property.
- 06~13 phút
Resource abstraction và @SpringBootApplication — nạp resource và bootstrap container
Bài này bóc 2 thứ liên quan chặt đến nhau: Resource interface trừu tượng hoá classpath/file/URL thành một API duy nhất, và @SpringBootApplication = 3 annotation hợp lại bootstrap container không magic. Hiểu 2 cơ chế này giải thích vì sao classpath: hay dùng nhất khi đóng gói jar, vì sao đặt App ở root package, và vì sao Spring Boot chỉ cần 1 context duy nhất.
- 07~30 phút
Mini-challenge: tự build mini IoC container 80 dòng
Bài thực hành khép lại Module 1 — code 1 IoC container đơn giản đủ tính năng: scan @Component, resolve dependency qua constructor, lifecycle @PostConstruct. Chứng minh Spring không phải magic — chỉ là reflection + topological sort + map cache.
- 08~5 phút
Container Internals — tổng kết
Tóm tắt module Container internals: data structure container, refresh() 12 bước, BFPP vs BPP, PropertySource ordering, bootstrap. Cheat sheet + self-assessment.