user5479362
user5479362

Reputation:

Creating PostgreSQL DataSource via pax-jdbc config file on karaf 4

On my karaf 4.0.8 I've installed the feature pax-jdbc-postgresql. The DataFactory for PostgreSQL is installed:

org.osgi.service.jdbc.DataSourceFactory]
osgi.jdbc.driver.class  org.postgresql.Driver
osgi.jdbc.driver.name   PostgreSQL JDBC Driver
osgi.jdbc.driver.version    PostgreSQL 9.4 JDBC4.1 (build 1203)
service.bundleid    204
service.scope   singleton
Using Bundles   com.eclipsesource.jaxrs.publisher (184)

I've create the file etc/org.ops4j.datasource-psql-sandbox.cfg:

osgi.jdbc.driver.class=org.postgresql.Driver
osgi.jdbc.driver.name=PostgreSQL
url=jdbc:postgresql://localhost:5432/sandbox
dataSourceName=psql-sandbox
user=sandbox
password=sandbox

After that, I see the confirmation in karaf.log that the file was processed:

2017-02-10 14:54:17,468 | INFO | 41-88b277ae0921) | DataSourceRegistration | 154 - org.ops4j.pax.jdbc.config - 0.9.0 | Detected config for DataSource psql-sandbox. Tracking DSF with filter (&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=org.postgresql.Driver)(osgi.jdbc.driver.name=PostgreSQL))

However, I see no new DataSource in services list in console. What went wrong? I see no exceptions in log ....

Upvotes: 2

Views: 1831

Answers (1)

Christian Schneider
Christian Schneider

Reputation: 19606

The log message tell you that the config was processed and it is now searching for a suitable DataSourceFactory OSGi service.

The problem in your case is that it does not find such a service. So to debug this you should list all DataSourceFactory services and check their properties.

service:list DataSourceFactory

In my case it shows this:

[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = org.postgresql.Driver
osgi.jdbc.driver.name = PostgreSQL JDBC Driver
...

As you see it does not match the filter you see in the log. Generally you should only provide either osgi.jdbc.driver.class or osgi.jdbc.driver.name not both. If you remove the osgi.jdbc.driver.name line the config will work.

There is no error message as the system can not know if the error is transient or not. Basically as soon as you install a matching OSGi service the DataSource will be created.

Upvotes: 2

Related Questions