简体   繁体   中英

Bundle in Karaf using wrong pax-jdbc DataSource

We have different OSGi bundles loaded in Karaf 4.0.3 and multiple javax.sql.DataSource loaded by pax-jdbc-config . For example, there are configured two datasources to different databases:

karaf@root()> service:list DataSource
[javax.sql.DataSource]
----------------------
 dataSourceName = datasourceA
 felix.fileinstall.filename = file:/opt/karaf/etc/org.ops4j.datasource-dba.cfg
 osgi.jdbc.driver.name = mysql-pool
 osgi.jndi.service.name = datasourceA
 password = secretpassword
 service.bundleid = 207
 service.factoryPid = org.ops4j.datasource
 service.id = 276
 service.pid = org.ops4j.datasource.2ab06071-d3fa-4d7e-b508-19f36892cb7e
 service.scope = singleton
 url = jdbc:mysql://mysql.example.com/dba
 user = dbuser
Provided by : 
 OPS4J Pax JDBC Config (207)
Used by: 
 MODULE B (29)

[javax.sql.DataSource]
----------------------
 dataSourceName = datasourceB
 felix.fileinstall.filename = file:/opt/karaf/etc/org.ops4j.datasource-dbb.cfg
 osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool
 osgi.jndi.service.name = datasourceB
 password = secretpassword
 service.bundleid = 207
 service.factoryPid = org.ops4j.datasource
 service.id = 278
 service.pid = org.ops4j.datasource.a7b84423-a605-4010-9806-db7bcc0bccd4
 service.scope = singleton
 url = jdbc:postgresql://postgresql.example.com/dbb
 user = dbuser
Provided by : 
 OPS4J Pax JDBC Config (207)

My problem is that bundle MODULE B should use datasourceB . It is configured to use datasourceB in all source files and in blueprint.xml

...
<reference id="datasourceB" interface="javax.sql.DataSource"/>
...

I really don't understand, how easily can karaf bundles use different DataSource.

And when datasourceA config file is removed, then MODULE B correctly use datasourceB .

Is this issue about wrong order of config files or something?

EDIT :
I have found out that when I remove datasourceA config file and therefore Karaf removes that DataSource (not present in service:list DataSource ), MODULE B correctly uses datasourceB .

But I still don't know why is this happening. Did I missed read some documentation about this? Is it pax-jdbc-config issue or Karaf issue?

引用数据源时,可以使用过滤器指示所需的哪一个:

<reference id="datasourceB" interface="javax.sql.DataSource" filter="(dataSourceName=datasourceB)" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM