Announcement Announcement Module
Collapse
No announcement yet.
Spring in eclipse RCP - JDBC Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring in eclipse RCP - JDBC Problem

    Anyone meet this problem?

    I can make sure that classes12.jar in my classpath already.

    Error:
    org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]; nested exception is java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver


    applicationContext.xml:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName"><value>oracle.jdbc.driver.O racleDriver</value></property>
    <property name="url"><value>XXXX</value></property>
    <property name="username"><value>XXXX</value></property>
    <property name="password"><value>XXX</value></property>
    </bean>

  • #2
    Most likely a class loader issue--would seem that the class loader that loaded your Spring JARs can't see the Oracle JAR. What environment are you in? A deployed environment or outside a container? Can you connect to Oracle without Spring?

    And no, I haven't seen this problem before, and I use Oracle extensively.

    Comment


    • #3
      Thanks
      I'm using Eclipse 3.0 and developing a plugin for RCP in Window2K.
      I can run smoothly when I just using Maven test case. But not work when integrate with eclipse plugin.

      Oh yes...it is the problem from class loader. And I have downloaded a source code from this site http://folk.uio.no/olepaa/spring/
      it can help me to solve some of the problem.
      For example : load the applicationContext.xml , load the classes12.jar etc.

      But now ..the problem come out again.
      I'm using ibatis in spring. It can read the sql-map-config.xml .
      But it can't get the DTD file

      --- The error occurred in the SQL Map Configuration file.
      --- Cause: com.ibatis.sqlmap.client.SqlMapException: XML Parser Error. Cause: org.xml.sax.SAXException: Fatal Error: URI=null Line=3:

      Even I have tried to use this
      <!DOCTYPE sqlMapConfig
      PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
      "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

      error like that
      --- The error occurred in the SQL Map Configuration file.
      --- Cause: com.ibatis.sqlmap.client.SqlMapException: XML Parser Error. Cause: org.xml.sax.SAXException: java.io.IOException: Could not find resource com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd
      Caused by: org.xml.sax.SAXException: java.io.IOException: Could not find resource com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd

      I don't know what happen in reading the DTD with spring in RCP.

      Comment


      • #4
        i have the same problem

        i have the same problem.
        i use hibernate integrated with spring ,and use them all in eclipse rcp application, but can't find sss.hbm.xml.

        i am not familiar with classloader, not know the matter about spring's classloader and eclipse's classloader.are there some detail introduction?

        thans a lot.

        Comment


        • #5
          The same problem

          I have the same problem as you. Can't my start application context. It doesn't find the classes.

          Anyone got it? Please help

          Comment


          • #6
            I also faced that problem trying to use a Hessian proxy service. Tried the solution provided by ryanhowai but it didn't fixed it completely.

            But after debugging for a while, I found a simple fix that, at least for now, makes everything work (although I feel it's not the most elegant way to fix it and will keep an eye on it in case I detect any problem).

            Basically, the problem is that Spring, when trying to instantiate some classes, uses this:

            Code:
            Thread.currentThread&#40;&#41;.getContextClassLoader&#40;&#41;
            Problem is that the thread that Spring gets is the one that starts up the Eclipse environment and its class loader has no information at all about the plugin's class loader, so that's why Spring cannot find any class.

            So, in the end, what I did to fix the problem was, in my RCP application class, write the following code:

            Code:
            Thread.currentThread&#40;&#41;.setContextClassLoader&#40;ACApplication.class.getClassLoader&#40;&#41;&#41;
            After that, Spring was being instantiated properly and my application was able to use everything without a problem. Did that 'cause the original ClassLoader only had three (or four, don't remember) classes available: the Eclipse Main launcher and some inner classes, so I thought I wasn't going to overwrite something necessary later on.

            As a conclusion, I think the root of the problem lies on the way Eclipse is instantiated and how it instantiate the available plugins.

            Hope this is helpful for somebody.

            Regards,
            Ivan

            Comment


            • #7
              Ivan, I've tried your solution and it doesn't works for me.
              I've wrote Thread.currentThread().setContextClassLoader(ACApp lication.class.getClassLoader()) on the constructor of my application class, the class that implements IPlatformRunnable. It changes the classloader from to sun.misc.Launcher$AppClassLoader to org.eclipse.core.runtime.adaptor.EclipseClassLoade r but it doesn't solve the problem. I've forgot anything?

              Comment


              • #8
                Juan, this is my application class:

                Code:
                public class ACApplication implements IPlatformRunnable &#123;
                	static &#123;
                		Thread.currentThread&#40;&#41;.setContextClassLoader&#40;ACApplication.class.getClassLoader&#40;&#41;&#41;;
                	&#125;
                	
                	private static final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext&#40;"/config/application-context.xml"&#41;;
                	
                	public static IServicios getServicios&#40;&#41; &#123;
                		return &#40;IServicios&#41;ctx.getBean&#40;"Servicios"&#41;;
                	&#125;
                I did nothing else anywhere and I have no problems getting my services bean. Try this approach as I have no constructor in my class and let us know if it works.

                Cheers,
                Ivan

                Comment


                • #9
                  Ivan

                  It doesn't works.

                  I was using a FileSystemXmlApplicationContext because ClassPathXmlApplicationContext didn't work. So, following your example I've replaced then File... by Class... and it throws a exception telling me that can't find the file.

                  Caused by: org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open class path resource [spring/applicationContext.xml]

                  Do you know why can't find it in the classpath. The file applicationContext.xml is in folder called spring inside config folder which is a class folder. I use the same in a non Eclipse RCP application and works fine.

                  Thanks.

                  Comment


                  • #10
                    Originally posted by Juan Gil

                    Caused by: org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open class path resource [spring/applicationContext.xml]

                    Do you know why can't find it in the classpath. The file applicationContext.xml is in folder called spring inside config folder which is a class folder.
                    Then I think you should use "config/spring/applicationContext.xml" to read the file, shouldn't you?

                    Comment


                    • #11
                      Hello Ivan.

                      I use /config/spring/applicationContext.xml , config/spring/applicationContext.xml, /spring/applicationContext.xml and spring/applicationContext.xml and it doesn't work.

                      I also copy applicationContext.xml to the root and use applicationContext.xml directly and it doesn't work.

                      Thanks.

                      Comment

                      Working...
                      X