Home Tutorial Spring Spring3 Ioc Spring Props Tag, Spring prop key, Spring props prop

 
 

Share on Google+Share on Google+
Spring Props Tag, Spring prop key, Spring props prop
Posted on: August 13, 2010 at 12:00 AM
Advertisement
In this spring tutorial you will see the example of spring props tags.

Spring Props

The Spring Framework has bean support for the Collections. It provide list, set, map and props elements. Here in this tutorial you will see about the props elements which is used to set values into   the properties.

CollegeBean.java

package collection.props.example;

import java.util.Properties;

public class CollegeBean {
  private Properties pros;

  public Properties getPros() {
    return pros;
  }

  public void setPros(Properties pros) {
    this.pros = pros;
  }

  @Override
  public String toString() {
    return "College [Props=" + pros + "]";
  }
}

PropsMain.java

package collection.props.example;

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

public class PropsMain {
  public static void main(String[] args) {
    BeanFactory beanfactory = new ClassPathXmlApplicationContext(
        "context.xml");
    CollegeBean coll = (CollegeBeanbeanfactory.getBean("collegeBean3");
    System.out.println(coll);
  }
}

context.java

  <!-- Spring Props -->

  <bean id="collegeBean3" class="collection.props.example.CollegeBean">
    <property name="pros">
      <props>
        <prop key="roll">100</prop>
        <prop key="name">satya</prop>
      </props>
    </property>
  </bean>

  <!-- End -->

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

College [Props={roll=100, name=satya}]

Download this example code

Advertisement

Related Tags for Spring Props Tag, Spring prop key, Spring props prop:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 13, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com