Java Reference
In-Depth Information
12-2. How do I get Started Using Spring Dynamic Modules?
Problem
You've got a feeling for how OSGi works, what it's capable of, and even how to go about creating a simple
“hello, world!” example. Now, you want to start using Spring to smooth over some of the minutiae of
resource acquisition and to help build more reliable systems in an OSGi environment.
Solution
Use Spring Dynamic Modules to provide the integration. Spring Dynamic Modules is a framework on
top of OSGi that works with any OSGi environment. It provides tight integration for Spring dependency
injection in the world of OSGi, which includes support for things like application context discovery,
interface-based service injection, and versioning.
Approach
Spring Dynamic Modules is a very powerful API for integration with the OSGi environment. You
need the Spring framework itself, and the Spring OSGi jars, as well. If you're following along using
Maven, the jars can be added by using SpringSource's OSGi bundle repository. This repository exports
the Spring framework jars, as well as those of countless other open source projects, in an OSGi-friendly
format under a Maven/Ivy-friendly repository. For more information on the repositories, see
http://www.springsource.com/repository/app/faq . To get access to them from Maven, add the
repositories to your pom.xml configuration file, at the bottom, before the closing </project> element:
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle
Releases</name>
<url> http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle
Releases</name>
<url> http://repository.springsource.com/maven/bundles/external</url>
</repository>
The SpringSource Enterprise Repository provides numerous OSGi-friendly jars files. To see if yours
is already supported, search for it at http://www.springsource.com/repository .
We'll use this infrastructure to rebuild our previous helloworld example, this time relying on Spring
to provide the injection of the service itself and to make writing the client more in line with what we've
come to expect from Spring development. We've already deployed the service, so we don't need to
rework any of that. Let's instead concentrate on a new client bundle.
Let's explore our revised client code. The entirety of the client is one Java class and two Spring XML
application context files. One file has the OSGi-friendly Spring Dynamic Modules namespace imported;
the other is a standard Spring application context.
 
Search WWH ::




Custom Search