top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to inject a java.util.Properties into a Spring Bean?

+1 vote
872 views
How to inject a java.util.Properties into a Spring Bean?
posted Aug 14, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Properties object is similar to Map based collection, only difference is keys also strings and values also strings. In case of Map based collection key can be any object and value also can be any object.

To inject Properties into a spring bean following steps are involved: –

Step 1: –Make java.util.Properties type variable as dependency in the spring bean.
Step 2:-To indicate the spring container to create the Properties object make use of tag.
Step 3: –To specify each element of the Properties object make use of tag.

e.g.: –

<bean name=”h” class=”com.nit.spring.HelloBean”>
 <property name=”properties”>
   <props>
     <prop key=”name”> Rama < /prop>
        <prop key=”address”> Hyderabad < /prop>
   < /props>
 < /property>
< /bean>

Note: –value of the key attribute becomes the key of the properties of Properties object. The content of tag become value of the property of Properties object.

answer Nov 7, 2017 by Manikandan J
...