As a new de facto industrial standard, OSGi has received wide attention, its service-oriented (interface) basic idea and the capability of dynamic module deployment are the goals that enterprise applications have been pursuing for a long time. Spring is a well-known lightweight Java development framework characterized by interface-oriented programming and non-invasive dependency injection. The combination of OSGi and Spring can give full play to their respective strengths, better meet the needs of enterprise-level application development. In 2008, the Spring Development Organization released the first version of the combination of OSGi and Spring: SPRING-DM. This paper presents a simple example of how to use SPRING-DM to develop WEB applications based on OSGi and Spring architectures, while exploring the key technologies and their basic ideas.
Develop a simple example of an OSGi Web application
A simple Web application
We write a simple WEB application compute.html: Compute the sum or product of two digits. As shown in the following illustration:
Figure 1. A simple example
To reflect the dynamic deployment capabilities of the OSGi bundle, we write two service bundle, one of which computes two digits and (called Add bundle), and the other calculates the product of two digits (called multiply bundle). When we click on the "Compute" button, if the add bundle is deployed at this time, the page will return two digits of the and, otherwise if the multiply bundle is deployed at this time, the page will return two number of the product. Development environment Preparation
1. Download Eclipse 3.4
2. Get all the plug-ins for OSGi, Equinox, and Spring, as shown in the following illustration:
1. Open Eclipse, set target platform to the above plug-in collection