下面的例子是用來展示基於XML配置元數據的基礎要素:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>
id屬性是一個字符串,這個字符串用來定義這個單獨的、唯一的bean,class屬性定義這個bean的類型,並且是使用完整的類名。id屬性的值是其協作對象。這個例子沒有展示XML指定協作對象。想了解更多可看“依賴性”章節。