Difference between p-namespace and c-namespace in Spring

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

Replied on January 18, 2016
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"/>

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.

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"/>

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

©2024 concretepage.com | Privacy Policy | Contact Us