[英]How to use an OSGI reference from another bundle in java
Im working with JBoss Fuse, I have created a bundle that exports a DataSouce and now I want to query it. 我在与JBoss Fuse一起工作时,创建了一个导出DataSouce的捆绑软件,现在我想查询它。
There's a reference to said DataSource in the blueprint of another bundle: 在另一个捆绑软件的蓝图中有一个提到的DataSource的引用:
<reference
id="myDataSource"
filter="(osgi.jndi.service.name=myDataSouce)"
interface="javax.sql.DataSource"
/>
How can I access this reference from java code so I can query it? 如何从Java代码访问此引用,以便对其进行查询?
You can create a custom Bean: 您可以创建一个自定义Bean:
<bean id="myDsBean" class="my.company.MyDsBean">
<property name="dataSource" ref="myDataSource" />
</bean>
Java code: Java代码:
public class MyDsBean {
private JdbcTemplate myds;
public void setDataSource(DataSource ds) {
this.myds = new JdbcTemplate(ds);
}
// Code to query data source
}
My example is using JdbcTemplate
but you can substitute that to whatever you want to use. 我的示例使用的是
JdbcTemplate
但您可以将其替换为想要使用的任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.