假设我有一节课
Person
具有属性
name
和
age
,并且可以像这样配置弹簧:
<beans:bean id="person" class="com.mycompany.Person">
<beans:property name="name" value="Mike"/>
<beans:property name="age" value="38"/>
</beans:bean>
我想为它提供一个定制的Spring模式元素,这很容易做到,允许我在Spring配置文件中包含以下内容:
<Person name="Mike" age="38"/>
架构定义如下所示:
<xsd:complexType name="Person">
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="age" type="xsd:int"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
基于此,现在让我们假设我想选择将我的自定义模式元素与SpringBean的传统元素和属性混合并匹配,因此我可以选择这样做:
<Person name="Mike">
<beans:property name="age" value="38"/>
</Person>