Spring Core & Boot/Container Internals — tổng kết
14/41
Bài 14 / 41~5 phútContainer InternalsMiễn phí lượt xem

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.

Bạn vừa mổ xong bên trong IoC container. Đây là bản đồ gói gọn để tra cứu nhanh.

Cheat sheet

Khái niệmMột câu cốt lõiBài
BeanFactoryHợp đồng tối thiểu: cho định danh → trả bean; mặc định lazy01
DefaultListableBeanFactoryTrái tim chứa bean: beanDefinitionMap (metadata) + singletonObjects (instance)01
Singleton scopeMột entry cached trong singletonObjects của một container — KHÔNG phải static pattern01
ApplicationContextBọc (compose) một DefaultListableBeanFactory + 4 capability; tạo eager singleton (fail-fast)01
refresh()12 bước, 3 giai đoạn: load definition → BFPP/BPP register → instantiate + publish event02
BeanDefinitionMetadata bean (class, scope, dependencies) trong beanDefinitionMap, chưa phải instance03
BFPP vs BPPBFPP modify metadata (trước instantiate); BPP modify instance (quanh từng bean)03
EnvironmentQuản properties + profiles; PropertySource ưu tiên command line cao nhất04
Relax bindingDB_URL env var → property db.url (chuẩn K8s/Docker)04
ResourceTrừu tượng hoá classpath:/file:/https:; classpath*: scan nhiều jar05
@SpringBootApplication= @SpringBootConfiguration + @EnableAutoConfiguration + @ComponentScan05

Mental model gói gọn

Một container = một DefaultListableBeanFactory = vài cái map. refresh() lấp đầy các map đó theo 12 bước. Bỏ chữ "magic", Spring container chỉ là Map<String, BeanDefinition> + Map<String, Object> cùng logic tra/tạo quanh chúng.

✅ Self-assessment

Bạn đã đạt module này nếu trả lời được:

  • Giải thích được BeanFactory vs ApplicationContext và data structure thật (singletonObjects, beanDefinitionMap)
  • Trace được refresh() 12 bước qua 3 giai đoạn biến config thành runtime container
  • So sánh được BeanFactoryPostProcessor (metadata) vs BeanPostProcessor (instance) và BeanDefinition
  • Cấu hình được externalized config với Environment + PropertySource đúng thứ tự ưu tiên
  • Chẩn đoán được lỗi container (bean không scan, sai thứ tự property) qua Resource + @SpringBootApplication

Liên hệ các module khác

Module tiếp theo: Bean Lifecycle & Scopes

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