Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring PropertyConfigurer - File Found but properties not getting resolved
    primarykey
    data
    text
    <p>I have a package for an executable jar.I want to externalise the db properties so I use a reference to a properties file from my appContext.xml.</p> <p>I have enabled TRACE level logging and I see that I don't get any errors against this line</p> <pre><code>&lt;context:property-placeholder location="classpath*:db.properties" ignore-unresolvable="true"/&gt; </code></pre> <p>However,further down when I try to access the properties configured in the file in my dataSource bean like </p> <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${db.driverClassName}"/&gt; &lt;property name="url" value="${db.url}" /&gt; &lt;property name="username" value="${db.username}" /&gt; &lt;property name="password" value="${db.password}" /&gt; &lt;/bean&gt; </code></pre> <p>I get the following error.</p> <pre><code>Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [${db.driverClassName}] </code></pre> <p>I have done the following to confirm that the file is being located correctly on the classpath</p> <ol> <li>I deliberately changed the property file name and I could see that I induced a FileNotFound Exception.</li> <li>I have verified the classpath contains a reference to this external property file.</li> </ol> <p>I'm not sure what I could be missing.Is there anything wrong in the way I refer to the property file or how I refer to the individual properties in my datasource bean ?</p> <p>I might as well add that I'm using Spring annotation for most beans and use the appcontext for declaration of datasource/transaction manager etc only.</p> <p>Please help,as I have now spent considerable time on this seemingly trivial piece and seemed to have hit a dead end.</p> <p><strong>the spring config file is here</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt; &lt;!-- Auto scan the components --&gt; &lt;context:component-scan base-package="patternengine" /&gt; &lt;context:annotation-config /&gt; &lt;tx:annotation-driven proxy-target-class="false"/&gt; &lt;aop:aspectj-autoproxy proxy-target-class="false"/&gt; &lt;context:property-placeholder location="classpath*:db.properties" ignore-unresolvable="true"/&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${db.driverClassName}"/&gt; &lt;property name="url" value="${db.url}" /&gt; &lt;property name="username" value="${db.username}" /&gt; &lt;property name="password" value="${db.password}" /&gt; &lt;/bean&gt; &lt;bean id="serviceArgs" class="com.splunk.ServiceArgs"&gt; &lt;property name="username" value="dashboardad" /&gt; &lt;property name="password" value="splunkuat" /&gt; &lt;property name="host" value="silrse.com" /&gt; &lt;property name="port" value="8089" /&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource"/&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;patternengine.entity.SplunkResult&lt;/value&gt; &lt;value&gt;patternengine.entity.MinuteGroupedSplunkResult&lt;/value&gt; &lt;value&gt;patternengine.entity.ApplicationComponent&lt;/value&gt; &lt;value&gt;patternengine.entity.ApplicationHostSourceDetail&lt;/value&gt; &lt;value&gt;patternengine.entity.ConfiguredApplication&lt;/value&gt; &lt;value&gt;patternengine.entity.ConfiguredException&lt;/value&gt; &lt;value&gt;patternengine.entity.IWatchTransaction&lt;/value&gt; &lt;value&gt;patternengine.entity.MinuteGroupedIWatchTransaction&lt;/value&gt; &lt;value&gt;patternengine.entity.AppMap&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p><strong>the property file is here</strong></p> <pre><code>db.driverClassName=oracle.jdbc.driver.OracleDriver db.url=jdbc:oracle:thin:@hdvash:1521:ECDDDDA01 db.username=rmt_perf_db db.password=qwerty123 </code></pre> <p><strong>the directory structure is as follows</strong> <img src="https://i.stack.imgur.com/9A2x3.jpg" alt="directory structure of the project is here"></p> <p><strong>the startup script is as follows</strong></p> <pre><code>JAVA_HOME=/home/a_cfp_asp/tomcat/tc7/7.0.39/java echo 'JAVA_HOME IS ' $JAVA_HOME PATH=$PATH:$java_home/bin #BASE_DIR='../' BASE_DIR='/home/a_cfp_asp/pattern_engine_2b/jobs/dataprocessor/' CONFIG_ROOT=$BASE_DIR'config' LIB_ROOT=$BASE_DIR'lib' jar_path=$LIB_ROOT/antlr-2.7.7.jar:$LIB_ROOT/aopalliance-1.0.jar:$LIB_ROOT/asm-3.1.jar:$LIB_ROOT/aspectjrt-1.6.11.jar:$LIB_ROOT/aspectjweaver-1.6.11.jar:$LIB_ROOT/avalon-framework-4.1.3.jar:$LIB_ROOT/cglib-2.2.jar:$LIB_ROOT/commons-lang3-3.0.jar:$LIB_ROOT/commons-logging-1.1.jar:$LIB_ROOT/dom4j-1.6.1.jar:$LIB_ROOT/hibernate-commons-annotations-4.0.1.Final.jar:$LIB_ROOT/hibernate-core-4.2.3.Final.jar:$LIB_ROOT/hibernate-entitymanager-3.6.8.Final.jar:$LIB_ROOT/hibernate-envers-4.2.3.Final.jar:$LIB_ROOT/hibernate-jpa-2.0-api-1.0.1.Final.jar:$LIB_ROOT/javassist-3.12.0.GA.jar:$LIB_ROOT/javassist-3.15.0-GA.jar:$LIB_ROOT/jboss-logging-3.1.0.GA.jar:$LIB_ROOT/jboss-transaction-api_1.1_spec-1.0.1.Final.jar:$LIB_ROOT/log4j-1.2.14.jar:$LIB_ROOT/logkit-1.0.1.jar:$LIB_ROOT/oracle-11.1.0.6.jar:$LIB_ROOT/pe-common-1.0.jar:$LIB_ROOT/pe-dataprocessor.jar:$LIB_ROOT/slf4j-api-1.6.1.jar:$LIB_ROOT/splunk-1.1.0.jar:$LIB_ROOT/spring-aop-3.1.1.RELEASE.jar:$LIB_ROOT/spring-asm-3.1.1.RELEASE.jar:$LIB_ROOT/spring-beans-3.1.1.RELEASE.jar:$LIB_ROOT/spring-context-3.1.1.RELEASE.jar:$LIB_ROOT/spring-context-support-3.1.1.RELEASE.jar:$LIB_ROOT/spring-core-3.1.1.RELEASE.jar:$LIB_ROOT/spring-expression-3.1.1.RELEASE.jar:$LIB_ROOT/spring-jdbc-3.1.1.RELEASE.jar:$LIB_ROOT/spring-orm-3.1.1.RELEASE.jar:$LIB_ROOT/spring-tx-3.1.1.RELEASE.jar config_path=$CONFIG_ROOT/db.properties MYCLASSPATH=.:$config_path:$jar_path java -cp$MYCLASSPATH com.patternengine.service.impl.DataProcessorService "Dashboard Application" 30 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload