Ok, so here’s what we basically do to start OSGi/Spring/JDBC:
1. Create 2 OSGi bundles, Main and DAO.
2. In DAO, create com.you.dao.SomeDAO interface and com.you.dao.impl.SomeDAOImpl. DAO will have DataSource param and some JDBC stuff that it does.
3. In META-INF/MANIFEST.mf add com.you.dao to export packages.
4. In META-INF/spring (create it) create 2 xml files, one will create SomeDAOImpl (named ’someDAO’) and map DataSource to it (it includes DataSource bean definition as well, to be quick), second one will expose SomeDAOImpl under its interface SomeDAO to OSGi. Like:
<osgi:service id=”someDAOOSGiService” ref=”someDAO”
interface=”com.you.dao.SomeDAO”>
</osgi:service>
5. In Main, create some class (MainClass) and a parameter for SomeDAO. We’ll use it later
6. In Main, make sure META-INF/MANIFEST.mf imports com.you.dao package. Also, META-INF/spring of this bundle needs to ‘catch’ SomeDAO:
<osgi:reference id=”someDAOService” interface=”com.you.dao.SomeDAO”/>
Also, we need to link this bean to HelloClass like this:
<bean name=”helloClass” class=”…HelloClass” init-method=”start”>
<property name=”webSiteDAO” ref=”webSiteDAOService”/>
</bean>
7. Now in helloClass we can create “public void start()” method and use SomeDAO.
8. Dependencies. Just like it’s written here, but including my comment in previous post. Don’t forget to create New Project – Plug-in Development – Plug-in From existing JAR archive and include commons-logging.jar there.