知识卡片
库携带配置会变隐性契约
库附带的可变配置或公开容器对象会被消费者依赖,配置一改就可能破坏服务。共享库宜提供合理默认值与显式可选参数,让服务保有配置所有权。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第4章《Anti-Patterns: Internal Shared Libraries》(源文件:`_epub-src/OPS/ch04.xhtml`,归一化正文 [29459:33672))
- 结论依据:原文指出库只宜附带静态且少变的配置,并建议默认值与消费者自定义,避免在共享库发布 Spring Bean 配置。
- 原始内容:Libraries can ship configuration if they are static and rarely or never change. If they change frequently, this is a bad idea. The same principle applies to services; however, services should own 43 all their configurations. Configurations should be externalized 44 . A better approach would be: do not use Spring in your internal shared libraries. Don’t ship spring beans as configs.