java - Spring+Maven Property File not loading -


i trying access property file containing db configurations in maven + spring project.

i following error:

cannot load jdbc driver class '${db_driver}'

my property file placed in src/resources folder.

below tag load property files:

<bean id="dbpropertyreader"          class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">         <property name="order" value="1" />         <property name="locations">             <value>classpath:${appenv.deployment}.properties</value>         </property>     </bean> 

following tag uses properties loaded:

<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close">         <property name="url" value="${db_url}" />         <property name="driverclassname" value="${db_driver}" />         <property name="username" value="${db_username}" />         <property name="password" value="${db_password}" /> </bean> 

below contents of properties file:

#jdbc properties db_driver=com.mysql.jdbc.driver db_url=jdbc\:mysql\://hostname\:3306/xxx_dbxxx?useunicode\=true db_username=abcdefgh db_password=ijklmnopq db_removeabadoned=true db_initialsize=1 db_maxactive=2 

${appenv.deployment} vmargument set follows:

-dappenv.deployment=development 

i have checked, value getting populated properly.

i getting following line in logs:

found key 'appenv.deployment' in [systemproperties] type [string] , value 'development'

then after getting following:

loading properties file class path resource [development.properties]

but how, values not getting loaded.

spring-datasource.xml

<beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">      <bean id="dbpropertyreader"          class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">         <property name="order" value="1" />         <property name="locations">             <value>classpath:${appenv.deployment}.properties</value>         </property>     </bean>      <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close">         <property name="url" value="${db_url}" />         <property name="driverclassname" value="${db_driver}" />         <property name="username" value="${db_username}" />         <property name="password" value="${db_password}" />         <property name="initialsize" value="${db_initialsize}" />         <property name="maxactive" value="${db_maxactive}" />     </bean>      <bean id="firstconfigdatafromdb" class="org.apache.commons.configuration.databaseconfiguration">         <constructor-arg type="javax.sql.datasource" ref="datasource" />         <constructor-arg index="1" value="tablename1" />         <constructor-arg index="2" value="propertyname2" />         <constructor-arg index="3" value="propertyvalue2" />     </bean>      <bean id="firstconfigdatafromdbfactory"         class="org.springmodules.commons.configuration.commonsconfigurationfactorybean">         <constructor-arg ref="firstconfigdatafromdb" />     </bean>      <!-- db properties initialization -->      <bean id="firstconfigurationplaceholder"         class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">         <property name="order" value="2" />         <property name="ignoreunresolvableplaceholders" value="false"/>         <property name="properties" ref="firstconfigdatafromdbfactory" />     </bean>      <bean id="secondconfigurationfromdb"         class="org.apache.commons.configuration.databaseconfiguration">          <constructor-arg type="javax.sql.datasource" ref="datasource" />         <constructor-arg index="1" value="tablename2" />         <constructor-arg index="2" value="propertyname2" />         <constructor-arg index="3" value="propertyvalue2" />     </bean>      <bean id="secondconfigurationfromdbfactory"         class="org.springmodules.commons.configuration.commonsconfigurationfactorybean">         <constructor-arg ref="secondconfigurationfromdb" />     </bean>      <!--      error map initialization      subtype of org.springframework.beans.factory.config.propertyplaceholderconfigurer     -->      <bean id="secondconfigurationplaceholder"         class="com.application.secondconfigurationplaceholder">         <property name="order" value="3" />         <property name="ignoreunresolvableplaceholders" value="false"/>         <property name="properties" ref="secondconfigurationfromdbfactory" />     </bean>  </beans> 

generic.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" >     <!-- enable annotation scanning -->     <context:annotation-config/>     <!-- initialise connection database -->     <import resource="spring-datasource.xml"/>     <!-- initialize mail connection -->     <import resource="spring-mail.xml"/>     <!-- inject database connection dao -->     <import resource="spring-dao.xml"/>      <!-- other beans below -->  </beans> 

applicationcontext.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" >     <import resource="generic.xml" />      <bean id="applicationbean" class="com.application.applicationbean" scope="singleton" >         <property .. />         <property .. />     </bean>  </beans> 

i loading applicationcontext.xml following statement in code:

`appcontext = new classpathxmlapplicationcontext("applicationcontext.xml");` 
  • applicationcontext.xml imports generic.xml.

  • generic.xml imports spring-datasource.xml.

have added application context file

<context:property-placeholder location="path .properties file"/>

add line before beans


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -