Part II. Reference Documentation

Document structure

This part of the reference documentation explains the core functionality offered by Spring Dynamic Modules.

Chapter 3, Bundles and Application Contexts describes the relationship between an OSGi Bundle and a Spring Application Context, and introduces the Spring Extender Bundle support for instantiating application contexts automatically.

Chapter 4, Packaging and Deploying Spring-based OSGi applications describes how to deploy the Spring Framework jar files in an OSGi environment, and how to reference external APIs from your application bundles should you need to do so. This chapter also explains some of the issues to be aware of when using existing enterprise libraries not designed for OSGi in an OSGi environment.

Chapter 5, The Service Registry describes how to export Spring beans as services in the OSGi service registry, and how to inject references to OSGi services into beans. This chapter also defines how the dynamic life-cycle of OSGi services and bundles is supported.

Chapter 6, Working with Bundles describes how to declare a bean that represents an OSGi bundle, including support for installing new bundles into the OSGi platform.

Chapter 7, Testing OSGi based Applications explains the integration testing support provided by Spring Dynamic Modules. This support enables you to write simple JUnit integration tests that can start up an OSGi environment, install the bundles needed for the integration test, execute the test case(s) inside of OSGi, and return the results to the runner. This makes it easy to integrate OSGi integration testing into any environment that can work with JUnit.

Table of Contents

3. Bundles and Application Contexts
The Spring Dynamic Modules Extender bundle
Application Context Creation
Mandatory Service Dependencies
Application Context Service Publication
Bundle Lifecycle
The Resource abstraction
Accessing the BundleContext
Application Context Destruction
Stopping the extender bundle
4. Packaging and Deploying Spring-based OSGi applications
Bundle format and Manifest headers
Required Spring Framework and Spring Dynamic Modules Bundles
Importing and Exporting packages
Considerations when using external libraries
Diagnosing problems
5. The Service Registry
Exporting a Spring bean as an OSGi service
Controlling the set of advertised service interfaces for an exported service
Controlling the set of advertised properties for an exported service
The depends-on attribute
The context-class-loader attribute
The ranking attribute
service element attribute
Service registration and unregistration lifecycle
Defining references to OSGi services
Referencing an individual service
Referencing a collection of services
Dealing with the dynamics of OSGi imported services
Listener and service proxies
Accessing the caller BundleContext
Exporter/Importer listener best practices
Listener and cyclic dependencies
Service importer global defaults
Relationship between the service exporter and service importer
6. Working with Bundles
7. Testing OSGi based Applications
OSGi Mocks
Integration Testing
Creating a simple OSGi integration test
Installing test prerequisites
Advanced testing framework topics
Creating an OSGi application context
Specifying the OSGi platform to use
Waiting for the test dependencies
Testing framework performance