<bean id= "cdPlay" class = "soundsystem.CDPlay">
<property name="compactDisc" red="compactDisc" />
</bean>
<Property> element is provided Setter method attribute features, Spring provides a simple alternative namespace p <property> element.
To enable p namespace, you need to head in the xml declaration
<?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- namespace naming rules and attributes followed c- namespace attribute types:
p: attribute name -ref = "injected beanId" // - ref: inject bean reference, tell spring is here assembled reference, rather than a literal value
The property is injected into the literal
<bean id = "cdPlayer" class="soundsystem.CDPlay" >
<property name = "title" value = "this is title name value">
</bean>
p namespace
<bean id = "cdPlayer" class="soundsystem.CDPlay"
p:title = "this is title name value"
p:artist = "this is artist value">
<Property name = "attribute name">
<list>
<value>this first value </value>
<value>this second value</value>
</list>
<property>
</bean>
And c namespace as bean reference assembly and the only difference is whether the assembly literal with "-ref" suffix, if no "-ref" suffix, the assembly is literal.
Although not be used to assemble a set of namespace p-, some features may be used Spring util- simplified namespace.
First, declare util- namespace and its model in 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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd>
...
</beans>
One of the functions provided by util- namespace is <util: list> element, it creates a list of bean:
<util:list id="listId">
<value> this is one value</value>
<value> this is two value</value>
</util:list>
<bean id = "compactDisc" class="soundsystem.BlankDisc"
p:title="this is title name"
p:artist = "this is a vale"
p: tracks-ref = "listId" /> // the attribute called tracks, depend above util: list created by the list bean.
Other elements util- namespace:
<util: Constant> a reference to a type of public static fields and exposed to bean
<Util: list> Create a java.util.list of bean, which contains reference values and
<Util: map> java.util.map create a type of bean, which contains reference values and
<Util: properties> to create a type of bean java.util.properties
<Util: property-path> creation attributes (or attributes embedded) in a ben, and exposed
<Util: set> java.util.Set create a type of bean, which contains reference values and