<bean id= "cdPlay" class = "soundsystem.CDPlay">
<property name="compactDisc" red="compactDisc" />
</bean>
<property>元素是为属性的Setter方法所提供的功能,Spring提供了简洁的p命名空间来替代<property>元素。
为启用p命名空间,需要在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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd>
...
</beans>
<bean id = "cdPlayer" class="soundsystem.CDPlay"
p:compactDisc-ref = "compactDisc" />
p-命名空间中属性所遵循的命名规则和c-命名空间属性类型:
<