使用其他捆绑软件中的服务接口时,OSGI捆绑软件需要jdbc驱动程序 [英] OSGI bundle requires jdbc driver when using service interface from other bundle
问题描述
我在Fuse ESB中部署了3个简单的捆绑包WebService,DataService和DataSource,每个捆绑包都使用带有用于连接bean和注册服务的蓝图的maven捆绑插件构建.数据源包包含连接详细信息,并通过JNDI注册Oracle jdbc数据源. DataService使用OpenJPA并具有DAO,域实体和服务接口实现,其中一种方法通过一种查询数据库的域实体并返回字符串的方法来实现.该服务接口是使用Export-Package导出的.
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.
Web服务引用了从DataService捆绑包导出的服务接口.
The web service has a reference to the service interface exported from the DataService bundle.
如果没有Web服务捆绑包导入oracle jdbc驱动程序,我将无法使此设置正常工作-我认为这是不需要的.我得到一个
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)
例外.
DataSource捆绑包将数据源作为服务导出到blueprint.xml中
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>
DataService在其persistence.xml中使用的
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>
此服务接口是从DataService服务包中导出的
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();
}
}
WebService捆绑包使用哪个
Which is used by the WebService bundle
@WebService
class WebService {
private Service service;
@WebMethod
public String getString() {
return service.getString();
}
}
推荐答案
您可以尝试将DataSource导出为OSGi服务吗?使用aries jndi,您仍然可以通过jndi使用它.这在Web服务捆绑包不知道oracle驱动程序的情况下应该可以工作.参见 http://www.liquid-reality.de/display/liquid/2012/01/13/Apache+Karaf+Tutorial+Part+6+-+Database+Access
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.
这篇关于使用其他捆绑软件中的服务接口时,OSGI捆绑软件需要jdbc驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!