XML Configuration using p-namespace by R4R Team

XML Configuration using p-namespace:-
The p-namespace enables you to use the bean element’s attributes, instead of nested <property/> elements, to describe your property values and/or collaborating beans.
Spring supports extensible configuration formats with namespaces, which are based on an XML Schema definition.

Let us take the example of a standard XML configuration file with <property> tags:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

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

<bean id="john-classic" class="com.example.Person">

<property name="name" value="John Doe"/>

<property name="spouse" ref="jane"/>

</bean>

<bean name="jane" class="com.example.Person">

<property name="name" value="John Doe"/>

</bean>

</beans>

Now the above Configuration can be written using p-namespace as follows;

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

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

<bean id="john-classic" class="com.example.Person">

p: name="name" value="John Doe"

p: name="spouse" ref="jane" />

</bean>

<bean name="jane" class="com.example.Person">

p: name="name" value="John Doe"/>

</bean> 

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!