Google News
logo
Java Springs - Interview Questions
How to Inject java.util.Properties into a Bean?
The first way is to use <props> tag as below.
 
<bean id="adminUser" class="com.freetimelearn.common.Customer">
  
    <!-- java.util.Properties -->
    <property name="emails">
        <props>
            <prop key="admin">admin@nospam.com</prop>
            <prop key="support">support@nospam.com</prop>
        </props>
    </property>
 
</bean>
 
You can use the “util:” namespace as well to create properties bean from a properties file and use bean reference for setter injection.
 
<util:properties id="emails" location="classpath:com/foo/emails.properties" />

Advertisement