Spring Props Tag, Spring prop key, Spring props prop
In this spring tutorial you will see the example of spring props tags.
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 = (CollegeBean) beanfactory.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