Can not find Driver when using generic database bundle

Posted by Marc on Stack Overflow See other posts from Stack Overflow or by Marc
Published on 2010-06-02T09:59:08Z Indexed on 2010/06/02 10:03 UTC
Read the original article Hit count: 308

I have a project that is build up from several OSGi bundles. One of them is a generic Database bundle that defines a DataSource that can be used throughout the project. The spring bean definition of this service is:

<osgi:service interface="javax.sql.DataSource">
    <bean class="org.postgresql.ds.PGPoolingDataSource">
        <property name="databaseName" value="xxx" />
        <property name="serverName" value="xxx" />
        <property name="user" value="xxx" />
        <property name="password" value="xxx" />
    </bean>
</osgi:service>

Now, when using this DataSource is a different bundle, we get an error:

No suitable driver found for jdbc:postgresql://localhost/xxx

I have tried the following to add the org.postgresql.Driver to the DriverManager:

  1. Instantiated an empty bean for that Driver in the spring context, like this:
    <bean class="org.postgresql.Driver" />

  2. Instantiated the Driver statically in one of the classes, like this:
    Class.forName("org.postgresql.Driver");

  3. Added a file META-INF\services\java.sql.Driver with the content org.postgresql.Driver

None of these solutions seems to help.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring