Home  >  Forum  >  Spring
Post New Query

Difference between p-namespace and c-namespace in Spring


joined on
August 11,2014
Asked on January 17,2016
What is difference between  p-namespace and c-namespace in Spring?

joined on
November 09,2013
Replied on January 18,2016

1.
p-namespace replaces <property> tag of <bean> in spring application context XML.

Suppose we have <bean> definition in XML as follows.

<bean id="comp" class="com.concretepage.bean.Company">
<property name="name" value="ABCD Ltd"/>
<property name="location" value="India"/>
</bean>

We can change <property> tag using p-namespace as follows.


<bean id="comp" class="com.concretepage.bean.Company" p:name="ABCD Ltd" p:location="India"/>

Find the link.


2.
c-namespace replaces constructor-arg of <bean> tag.

If we have constructor dependency injection as follows.

<bean id="city" class="com.concretepage.bean.City">
<constructor-arg name="cityName" value="Agra"/>
<constructor-arg name="population" value="1000"/>
</bean> 

We can replace constructor-arg using c-namespace as follows.

<bean id="city" class="com.concretepage.bean.City" c:cityName="Agra" c:population="1000"/>

Find the link.


Write Answer








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us