Announcement Announcement Module
Collapse
No announcement yet.
problem with accessing properties file. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with accessing properties file.

    Hi

    can anyboby help me out?
    I am getting error mesage as below..
    I am new to spring framework...



    May 15, 2007 4:18:50 PM org.springframework.context.support.AbstractApplic ationContext refresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@109a4c: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@109a4c]; startup date [Tue May 15 16:18:50 IST 2007]; root of context hierarchy
    May 15, 2007 4:18:50 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [spring-context.xml]
    %%%%%%%%%%%%%%%%%%%%%

    May 15, 2007 4:18:50 PM org.springframework.context.support.AbstractApplic ationContext refresh
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@109a4c]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@1f9dc36
    May 15, 2007 4:18:50 PM org.springframework.core.io.support.PropertiesLoad erSupport loadProperties
    INFO: Loading properties file from class path resource [jdbc.properties]
    May 15, 2007 4:18:50 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1f9dc36: defining beans [greetingService,propertyConfigurator,dataSource,jd bcTemplate,studentDao]; root of factory hierarchy
    May 15, 2007 4:18:50 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1f9dc36: defining beans [greetingService,propertyConfigurator,dataSource,jd bcTemplate,studentDao]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [spring-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateExcep tion; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [org.apache.derby.jdbc.ClientDriver]; nested exception is java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    Caused by: org.springframework.beans.PropertyBatchUpdateExcep tion; nested PropertyAccessException details (1) are:
    PropertyAccessException 1:
    org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [org.apache.derby.jdbc.ClientDriver]; nested exception is java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    Caused by: org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [org.apache.derby.jdbc.ClientDriver]; nested exception is java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.setDriverClassName(DriverManagerDataSour ce.java:148)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:821)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:645)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 8)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 9)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1100)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:835)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:144)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:279)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:360)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:91)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:75)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
    at com.testclient.HelloWorldApp.main(HelloWorldApp.ja va:19)

  • #2
    Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    It cannot find the driver for the derby datrabase. Make sure you have the correct jars in your classpath.

    Comment


    • #3
      Thanks a lot..
      Its working now.

      Comment


      • #4
        java.lang.ClassNotFoundException: &quot;org.apache.derby.jdbc.ClientDriver&quot;

        I am using netbeans and I have included the libraries into my classpath i.e. derby.jar, derbyclient.jar and I still get the same error. What other class path settings did you use.

        I have even tried running the application through a bat file and explicitly set the classpath but spring cannot load it either.

        pls help

        regards

        Comment


        • #5
          Originally posted by kin_o View Post
          I am using netbeans and I have included the libraries into my classpath i.e. derby.jar, derbyclient.jar and I still get the same error. What other class path settings did you use.

          I have even tried running the application through a bat file and explicitly set the classpath but spring cannot load it either.

          pls help

          regards
          -

          More Information :

          Spring applicationContext.xml:
          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
          <property name="locations">
          <list>
          <value>classpath:dbconnection.properties</value>
          </list>
          </property>
          </bean>

          <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> -->
          <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource" 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>


          dbconnection properties
          jdbc.driverClassName="org.apache.derby.jdbc.Embedd edDriver"
          jdbc.url="jdbc:derbyath-to-db"
          jdbc.username="APP"
          jdbc.password="APP"


          INFO: Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [propertyConfigurer,dataSource,transactionManager,b aseTransactionProxy,sqlMapClient,rmsTest,appUserDa o]; root of BeanFactory hierarchy}
          Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is PropertyAccessExceptionsException (1 errors)
          PropertyAccessExceptionsException (1 errors)
          org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class ["org.apache.derby.jdbc.EmbeddedDriver"]; nested exception is java.lang.ClassNotFoundException: "org.apache.derby.jdbc.EmbeddedDriver"
          org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class ["org.apache.derby.jdbc.EmbeddedDriver"]; nested exception is java.lang.ClassNotFoundException: "org.apache.derby.jdbc.EmbeddedDriver"
          java.lang.ClassNotFoundException: "org.apache.derby.jdbc.EmbeddedDriver"
          at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
          at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:242)
          at org.springframework.util.ClassUtils.forName(ClassU tils.java:109)
          at org.springframework.util.ClassUtils.forName(ClassU tils.java:87)
          at org.springframework.jdbc.datasource.DriverManagerD ataSource.setDriverClassName(DriverManagerDataSour ce.java:148)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:707)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:572)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:737)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:764)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:753)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1057)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:283)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:313)
          at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:87)
          at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:72)
          at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:63)
          at Launcher.StartApplication.main(StartApplication.ja va:32)

          Comment


          • #6
            However you are launching this, it must not be on that classpath.

            Comment


            • #7
              I am starting the application in my main class using the following :
              ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext .xml");

              thanks

              Comment


              • #8
                Originally posted by kin_o View Post
                I am starting the application in my main class using the following :
                ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext .xml");

                thanks
                Just a quick addition - This is outside a web container. Do I need to explicitly specify the data source using the DriverManagerDataSource ?
                thanks

                Comment


                • #9
                  As I said before the runtime classpath must not have the JAR.

                  Comment


                  • #10
                    I really think this is a spring issue. My dist folder contains i jar file and lib folder containing all the necessary jars as specified in my manifest below.

                    Manifest-Version: 1.0
                    Ant-Version: Apache Ant 1.6.5
                    Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
                    Main-Class: Launcher.StartApplication
                    Class-Path: lib/activation.jar lib/commons-dbcp-1.2.2.jar lib/commons-
                    pool-1.3.jar lib/derby.jar lib/derbyclient.jar lib/derbyLocale_de_DE.
                    jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocale_it.
                    jar lib/derbyLocale_ja_JP.jar lib/derbyLocale_ko_KR.jar lib/derbyLoca
                    le_pt_BR.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar lib/
                    derbynet.jar lib/derbyTesting.jar lib/derbytools.jar lib/ibatis-commo
                    n-2.jar lib/ibatis-dao-2.jar lib/ibatis-sqlmap-2.jar lib/mysql-connec
                    tor-java-5.0.6-bin.jar lib/spring-aop.jar lib/spring-beans.jar lib/sp
                    ring-context.jar lib/spring-core.jar lib/spring-dao.jar lib/spring-hi
                    bernate.jar lib/spring-jdbc.jar lib/spring-mock.jar lib/spring-orm.ja
                    r lib/spring-remoting.jar lib/spring-support.jar lib/spring-web.jar l
                    ib/spring-webmvc.jar lib/spring.jar lib/commons-logging-1.1.jar lib/c
                    ommons-logging-adapters-1.1.jar lib/commons-logging-api-1.1.jar lib/c
                    ommons-collections-3.2.jar
                    X-COMMENT: Main-Class will be added automatically by build

                    I have also been able to prove that I can load the driver without using spring by running the following piece of code

                    Code:
                    org.apache.derby.jdbc.EmbeddedSimpleDataSource ds = null;
                                Connection conn = null;
                                Properties props = new Properties();
                                props.put("user", "APP");
                                props.put("password", "APP");
                                try
                                {
                                    Class.forName(driver).newInstance();
                                } catch (ClassNotFoundException ex)
                                {
                                    ex.printStackTrace();
                                } catch (IllegalAccessException ex)
                                {
                                    ex.printStackTrace();
                                } catch (InstantiationException ex)
                                {
                                    ex.printStackTrace();
                                }
                                System.out.println("Loaded the appropriate driver.");
                                try
                                {
                                
                                    conn = DriverManager.getConnection(protocol, props);
                                } catch (SQLException ex)
                                {
                                    ex.printStackTrace();
                                }
                                System.out.println("Connected Successfully");
                                try
                                {
                                    conn.close();
                                } catch (SQLException ex)
                                {
                                    ex.printStackTrace();
                                }

                    Pls help and thanks for your comments so far.
                    regards

                    Comment


                    • #11
                      I still don't think it is a Spring issue...

                      Make sure that the classpaths are the same.

                      How do you run these applications? From a bat/sh file? Or double clicking something?

                      Comment


                      • #12
                        Thanks for your reply. I have tried running the application both from an ide and from a bat file. I use Netbeans which packages the jar and produces the lib dir in the dist folder. The jar contains the manifest with the classpath so I can run directly from netbeans or eclipse which I tried as well.

                        The second format I use is the bat file and there I set the classpath to my lib folder with all the jars and then run java -jar <jarname>.

                        Am I missing something.

                        regards

                        Comment


                        • #13
                          have you tried including the classpath in your java -jar <jarname> ? Also simply setting it to the lib folder isn't enough, you will have to append all the jars to the classpath.

                          Comment


                          • #14
                            Here is my bat file contents and I am running this from the dist directory.

                            REM Run from distribution dir
                            REM File in dist directory
                            REM TREMS.jar
                            REM lib/ (contains all necessary jar files)
                            REM Readme.txt
                            REM run.bat




                            set classpath=.;lib/activation.jar;lib/commons-dbcp-1.2.2.jar; lib/commons-pool-1.3.jar;lib/derby.jar;lib/derbyclient.jar; lib/derbyLocale_de_DE.jar; lib/derbyLocale_es.jar; lib/derbyLocale_fr.jar; lib/derbyLocale_it.jar;lib/derbyLocale_ja_JP.jar; lib/derbyLocale_ko_KR.jar; lib/derbyLocale_pt_BR.jar; lib/derbyLocale_zh_CN.jar; lib/derbyLocale_zh_TW.jar; lib/derbynet.jar; lib/derbyTesting.jar; lib/derbytools.jar; lib/ibatis-common-2.jar; lib/ibatis-dao-2.jar; lib/ibatis-sqlmap-2.jar; lib/mysql-connector-java-5.0.6-bin.jar; lib/spring-aop.jar; lib/spring-beans.jar; lib/spring-context.jar; lib/spring-core.jar; lib/spring-dao.jar; lib/spring-hibernate.jar; lib/spring-jdbc.jar; lib/spring-mock.jar; lib/spring-orm.jar lib/spring-remoting.jar; lib/spring-support.jar; lib/spring-web.jar; lib/spring-webmvc.jar; lib/spring.jar; lib/commons-logging-1.1.jar; lib/commons-logging-adapters-1.1.jar; lib/commons-logging-api-1.1.jar; lib/commons-collections-3.2.jar;%classpath%
                            java -jar TREMS.jar
                            pause

                            Comment


                            • #15
                              try
                              Code:
                              java -cp %CLASSPATH% -jar TREMS.jar

                              Comment

                              Working...
                              X