Spring p-namespace


 

Spring p-namespace

In this tutorial you will see the use of p-namespace in spring framework.

In this tutorial you will see the use of p-namespace in spring framework.

Spring p-namespace

In this tutorial you will see the use of p-namespace in spring framework. In spring generally we have nested <property/> elements, to describe your property values. You can do the same thing using the p-namespace also.

SpringBean.java

package spring.pnamespace.example;

public class SpringBean {
  private String message = "";

  public void setMessage(String mesg) {
    this.message = mesg;
  }

  public String getMessage() {
    return message;
  }

}

SpringMain.java

package spring.pnamespace.example;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringMain {
  public static void main(String[] args) {
    BeanFactory beanfactory = new ClassPathXmlApplicationContext(
    "context.xml");
    SpringBean bean = (SpringBeanbeanfactory.getBean("basic");
    System.out.println(bean.getMessage());
  }
}

context.java

<?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.xsd">
  <bean id="basic" class="spring.pnamespace.example.SpringBean"
    p:message="Message passing using p-namespace">
  </bean>
</beans>

When you run this application it will display output as shown below:


Message passing using p-namespace

Download this example code

Ads