扩展 Blueprint 以实现 SAB 容器
1. 扩展 Blueprint 的特性与优势
Blueprint 为 Java 组件提供了不同的作用域规则,如单例(singletons)或原型(prototypes),同时支持面向切面编程(AOP)。更为重要的是,它支持依赖注入的概念。依赖注入是一种设计模式,通过将组件之间的依赖从程序代码中解耦,从而最小化组件间的依赖关系,这一概念因 Spring 框架而广为人知。
2. 编写使用 SAB 特性的 Blueprint 文档
选择 XML 作为指定 Blueprint 文档的媒介并非偶然,XML 是实现扩展性的理想工具。以下是一个使用 SAB 特性的 Blueprint 文档示例:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sab=
"http://www.manning.com/xmlns/blueprint-sab/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/
blueprint/v1.0.0/blueprint.xsd
http://www