问题
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