java - how to read properties file using spring and exposed to class -
i using spring 3.0.5 , trying read properties files make kind of validation datasource. getting null when use @value ,below cfg.
in applicationcontext.xml
<bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="location" value="classpath:database.properties"/> <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="${jdbc.driverclassname}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean>// here establishing data-source.
the class want exposed values of properties file
@component public class propertyreaderbean { //@value("#{propertyconfigurer1[dailylimit]}") //@value("#{database['jdbc.driverclassname']}") @value("${jdbc.driverclassname}")// tried 3 still getting null private string limit; public string getlimit() { system.out.println(" limit : "+limit); return limit; } public void setlimit(string limit) { system.out.println(" limit : "+this.limit); this.limit = limit; }
and databse.properties file
jdbc.driverclassname=com.mysql.jdbc.driver jdbc.url=jdbc:mysql://localhost:3306/imps jdbc.username=root jdbc.password=root
so whenever trying access values properties file using above configuration, getting null, please guide.
update: setter method of propertyreaderbean not working, have checked stacktrace, when add in xml can read properties file values.
<bean id="propertydao" class="com.alw.imps.validator.propertyreaderbean"> <property name="limit" value="${jdbc.password}"></property> </bean>
a cause @value doesn't work. did declare < context:annotation-config /> in application context?
Comments
Post a Comment