Assembling values and references for bean properties using the <property> element is not too complex. However, Spring's namespace P provides a way to assemble another bean property without the need to configure so many angle brackets.
The schema URL for the namespace P is http://www.springframework.org/schema/p. If you want to use the namespace p, simply add the following statement to the XML configuration of spring:
<? XML version= "1.0" encoding= "UTF-8" ?> < xmlns= "Http://www.springframework.org/schema/beans" xmlns:p= "http ://www.springframework.org/schema/p " 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-3.0.xsd " >
(The above link may be wrong for hand, please check when copying)
With this declaration, we can now use P: as the prefix for all attributes of the <bean> element to assemble the bean's properties.
To demonstrate, I used the property to declare a bean and use the namespace p to declare a bean to compare it.
Property :<BeanID= "Kenny"class= "Com.springinaction.springidol.Instrumentalist"> < Propertyname= "Song"value= "Jingle Bells"/> < Propertyname= "instrument"ref= "Piano"/></Bean>P Namespace:<BeanID= "Kenny"class= "Com.springinaction.springidol.Instrumentalist"P:song= "Jingle Bells"P:instrument-ref= "Piano"/>
The value of the P:song property is set to "Jingle Bells", which will be used to assemble the song property. Similarly, the value of the P:instrument-ref property is set to "Piano", a bean with ID piano is used to assemble the instrument attribute, and the-ref suffix is used as an identity to tell spring to assemble a reference rather than a literal.
Select <property> or namespace p depending on you, they are equivalent. The main advantage of the namespace P is that it is more concise.
Using Spring's namespace p assembly properties-excerpt from the Spring Combat (3rd edition)