Spring – Inject Properties file into Bean

Problem Statement: Spring – Inject Properties file into Bean

Spring Bean configuration file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:properties id="propertiesFileID1" location="classpath:complete_file_pathfilename.properties"/>

<bean name="BeadID" class = "com.abc.ClassNameABCD" >
	<property name="propFile1" ref="propertiesFileID1"/>


Source code

package com.abc;

import java.util.Properties;

public class ClassNameABCD

 private Properties propFile1;

 //Prepare getter and setters for propFile1;


Read this for more information


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s