OSGI bundle requires jdbc driver when using service interface from other bundle

点点圈 提交于 2019-12-08 10:35:56

问题


I have 3 simple bundles WebService, DataService and DataSource deployed in Fuse ESB, each built using the maven bundle plugin with blueprint for wiring beans and registering services. The datasource bundle contains connection details and registers the Oracle jdbc datasource via JNDI. The DataService uses OpenJPA and has a DAO, domain entities and a service interface implementation with one method which queries the database for a domain entity and returns a string. The service interface is exported using Export-Package.

The web service has a reference to the service interface exported from the DataService bundle.

I can't get this setup to work without the web service bundle importing the oracle jdbc driver - which I thought wouldn't be needed. I get a

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver from bundle 430 (web-service-bundle)

exception unless I import the oracle.jdbc.driver package.

The DataSource bundle exports the data source as a service in the blueprint.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <!-- other properties go here -->
</bean>

<service ref="dataSource" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/dataSource" />
    </service-properties>
</service>

Which the DataService uses in it's persistence.xml

  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  <jta-data-source>osgi:service/jdbc/dataSource</jta-data-source>

This Service interface is exported from the the DataService service bundle

class SomeService implements Service {
    private Dao dao;
    public void String getString() {
        Entity entity = dao.getEntity();
        return entity.getString();
    }

}

Which is used by the WebService bundle

@WebService
class WebService {

    private Service service;

    @WebMethod
    public String getString() {
        return service.getString();
    }
}

回答1:


Can you try to export the DataSource as an OSGi service? Using aries jndi you can then still use it via jndi. This should work without the webservice bundle knowning the oracle driver. See http://www.liquid-reality.de/display/liquid/2012/01/13/Apache+Karaf+Tutorial+Part+6+-+Database+Access

For your exact example it would help to see the code.



来源:https://stackoverflow.com/questions/16892212/osgi-bundle-requires-jdbc-driver-when-using-service-interface-from-other-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!