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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
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_path\filename.properties"/>
<bean name="BeadID" class = "com.abc.ClassNameABCD" >
<property name="propFile1" ref="propertiesFileID1"/>
</bean>
</beans>
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
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-util-properties
Categories: Spring Frame work
Spring inject properties



