I have the following DataSource configuration file for PAX:
我有PAX的以下DataSource配置文件:
osgi.jdbc.driver.class=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/demo
dataSourceName=demo-pg
user=demo
password=demo
It creates DataSource in Karaf, however, in Eclipse, using Equinox OSGi launcher, I get NPE:
它在Karaf中创建了DataSource,然而,在Eclipse中,使用Equinox OSGi启动器,我获得了NPE:
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:459)
at java.util.Properties.setProperty(Properties.java:166)
at org.postgresql.ds.common.BaseDataSource.setProperty(BaseDataSource.java:1030)
at org.postgresql.ds.common.BaseDataSource.setUrl(BaseDataSource.java:964)
at org.postgresql.osgi.PGDataSourceFactory.configureBaseDataSource(PGDataSourceFactory.java:65)
at org.postgresql.osgi.PGDataSourceFactory.createSimpleDataSource(PGDataSourceFactory.java:127)
at org.postgresql.osgi.PGDataSourceFactory.createDataSource(PGDataSourceFactory.java:149)
at org.ops4j.pax.jdbc.config.impl.DataSourceRegistration.createDs(DataSourceRegistration.java:108)
at org.ops4j.pax.jdbc.config.impl.DataSourceRegistration.<init>(DataSourceRegistration.java:63)
at org.ops4j.pax.jdbc.config.impl.DataSourceFactoryTracker.addingService(DataSourceFactoryTracker.java:42)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)
at org.ops4j.pax.jdbc.config.impl.DataSourceConfigManager.updated(DataSourceConfigManager.java:80)
at org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker.updated(ManagedServiceFactoryTracker.java:159)
at org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker.provideConfiguration(ManagedServiceFactoryTracker.java:93)
at org.apache.felix.cm.impl.ConfigurationManager$UpdateConfiguration.run(ConfigurationManager.java:1772)
at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141)
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109)
at java.lang.Thread.run(Thread.java:745)
After inspecting in Debugger, I've found out, the error is thrown because property PROTOCOL_VERSION
is null. I've tried to set the variable in config file:
在调试器中检查后,我发现错误被抛出,因为属性PROTOCOL_VERSION为null。我试过在配置文件中设置变量:
protocolVersion=3
but I still get the same error.
但我仍然得到同样的错误。
How to configure PostgreSQL DataSource in Equinox/Eclipse runtime?
如何在Equinox / Eclipse运行时配置PostgreSQL DataSource?
I'm using PostgreSQL driver version 9.4-1200 :
我正在使用PostgreSQL驱动版本9.4-1200:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
</dependency>
2 个解决方案
#1
2
It seems resolved with new PostgreSQL 42.1.1 driver.
它似乎解决了新的PostgreSQL 42.1.1驱动程序。
A note on PAXJDBC PostgreSQL Driver Adapter page states:
关于PAXJDBC PostgreSQL驱动程序适配器页面的说明指出:
Current postgresql versions are valid bundles and also provide a DataSourceFactory. So if you use a recent version you will not need this adapter anymore.
当前的postgresql版本是有效的捆绑包,并且还提供DataSourceFactory。因此,如果您使用的是最新版本,则不再需要此适配器。
Try this driver:
试试这个驱动:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
#2
0
You might be hitting the issue PAXJDBC-107. Pax-jdbc-config uses reflection to write the properties. It currently works if the datasource has a setter with an Integer parameter but not with int. I plan to fix this in the next days and do a new release.
您可能会遇到问题PAXJDBC-107。 Pax-jdbc-config使用反射来编写属性。如果数据源具有带有Integer参数但不带int的setter,则它当前有效。我打算在接下来的日子里解决这个问题并做一个新版本。
#1
2
It seems resolved with new PostgreSQL 42.1.1 driver.
它似乎解决了新的PostgreSQL 42.1.1驱动程序。
A note on PAXJDBC PostgreSQL Driver Adapter page states:
关于PAXJDBC PostgreSQL驱动程序适配器页面的说明指出:
Current postgresql versions are valid bundles and also provide a DataSourceFactory. So if you use a recent version you will not need this adapter anymore.
当前的postgresql版本是有效的捆绑包,并且还提供DataSourceFactory。因此,如果您使用的是最新版本,则不再需要此适配器。
Try this driver:
试试这个驱动:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
#2
0
You might be hitting the issue PAXJDBC-107. Pax-jdbc-config uses reflection to write the properties. It currently works if the datasource has a setter with an Integer parameter but not with int. I plan to fix this in the next days and do a new release.
您可能会遇到问题PAXJDBC-107。 Pax-jdbc-config使用反射来编写属性。如果数据源具有带有Integer参数但不带int的setter,则它当前有效。我打算在接下来的日子里解决这个问题并做一个新版本。