Announcement Announcement Module
Collapse
No announcement yet.
datasource property resolution error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • datasource property resolution error

    I am trying to load properties into the datasource via a property file. The spring documentation says this will work, but it is failing for me.

    Code:
       <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="${jdbc.driver}"></property>
    		<property name="url" value="${jdbc.url}"></property>
    		<property name="username" value="${jdbc.username}"></property>
    		<property name="password" value="${jdbc.password}"></property>
        </bean>
    properties are set as:

    Code:
    jdbc.driver=oracle.jdbc.driver.OracleDriver
    jdbc.url=jdbc:oracle:thin:@localhost:1521:xe
    jdbc.username=system
    jdbc.password=system
    Getting the following error:
    Code:
    org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${jdbc.driver}'
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
    	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    	at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
    	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    	at com.mycompany.error.jms.ErrorJMSMesssageListener.onMessage(ErrorJMSMesssageListener.java:61)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
    	at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.ClassNotFoundException: ${jdbc.driver}
    	at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
    	at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
    	at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:305)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:246)
    	at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
    	at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:169)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
    	... 38 more

  • #2
    I suggest a read again it probably also tells you to register a PropertyPlaceHolderConfigurer...

    Comment


    • #3
      PropertyPlaceHolderConfigurer

      Marten, Thanks for your reply. I should have included that configuration in the post above.

      Code:
          <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
             <property name="locations">
                 <value>classpath:myApplication.properties</value>
             </property>
         </bean>
      I have another application, configured the same way, that use properties from a property file. It exhibits no problems. I do not configure a datasource in that application. It seems to be linked to the datasource only.

      Comment


      • #4
        Make sure that it is loaded in the same ApplicationContext. The PropertyPlaceHolderConfigurer is a BeanFactoryPostProcessor and operates ONLY on the BeanFactory it is defined in. It does not operate on parent or child contexts. So if your PPC is in the root context (ContextLoaderListener) and your datasource in the servlet (or vice-versa) it isn't going to work. Judging from the stack trace the datasource bean and/or the PPC are in different contexts, as else I would expect an error from the PPC.

        Also what I'm not getting is why is your ErrorJMSListener doing a getBean on a BeanFactory (I really hope it isn't instantiating a bean factory).

        Comment


        • #5
          Thank you for your help. I had not reviewed all of the code from other developers, and that was the problem. They were doing a getBean call. I have refactored the code for dependency injection, and the problem went away. Thanks again.

          Comment

          Working...
          X