Converting a Spring application to an OSGi application
To convert an application that is created using the Spring Framework to an OSGi application and move from the Spring Framework to standards-based technologies, you must modify the application manually. If a Spring application contains only web application archive (WAR) files, you can convert it automatically to run in OSGi Applications, but it still uses the Spring Framework.
About this task
In a Spring application, the Spring Framework manages features such as transactions, persistence, and dependency injection, and handles the communication between the servlets in the web container and the classes that handle the business logic of the application.
After you convert the application to an OSGi application that uses OSGi Applications support, the Blueprint Container manages the transactions, persistence and dependency injection.
If the application is an enterprise archive (EAR) file that contains only web application archive (WAR) files, you can convert it automatically. You might convert a Spring application in this way if a WAR file uses other library JAR files that must remain unchanged for the application to work. See Converting a web application archive file to an OSGi web application bundle.
Otherwise, you need to identify the Spring components and replace them with the equivalent code to make them plain old Java™ objects (POJOs), then modify the relevant XML files so that the Blueprint container manages those objects.
- Create a well-defined interface to delegate to. The interface represents the classes that handle the business logic of the application.
- Create a service for each class, so that the servlet in the web container can use them.
- Change code that is specific to the Spring Framework in the classes to use the equivalent in Java EE, for example Java EE persistence classes.
- Create a handler servlet and interface to replace those from the Spring Framework.
- Modify XML and manifest files to use syntax that is correct for the Blueprint Container.
At the end of each step, the application is still usable, so you can decide whether to make all, or just some, of these changes.
The following procedure describes these steps in more detail.