简体   繁体   中英

Migrating from Spring monolith application to OSGI

We have been building two suites of applications for the last 10 years using Spring as our dependency injection. We also use spring-batch and spring-amqp. We are now looking to move to OSGI so that our monolithic applications can be separated into bundles so that we can be more agile. The two suites are web applications and are deployed as two separate war files. We are looking to use Apache Karaf as our OSGI runtime.

Spring-DM is dead and it appears that we are going to have to convert EVERYTHING to use Blueprint for our dependency injection.

My question is how do we do this incrementally? It will be close to impossible to convert all of this over at once. It seems like one bundle should still be able to use Spring DI and have it's own application context as long as we take the responsibility to expose any services that we want to the service registry in the bundle activator, but I'm not sure if there is some kind of magic that we would lose like transaction management.

Any guidance on this would be really appreciated.

You might want to consider to make the problem appear even larger and switch to DS instead of Blueprint ... To take truly advantage of the OSGi model, DS is far superior to Blueprint in all aspects. In reality, after the first hurdle, you'll make much more progress and your gains will be higher. Though Blueprint made Spring available on OSGi, it never 'got' OSGi.

For strategy, keep your Spring app alive as a single bundle and move things out gradually. Ie the elephant approach.

The biggest gain that OSGi provides can be summarized as follows:

  • Make sure modules have service APIs that ONLY handle collaboration. Ie each service API should be a story/scenario how the actors work together, not how they come into existence and are configured.
  • Let Configuration Admin to the configuration work. Ie never expose configuration APIs. In OSGi, you register instances, not things that still need to be configured.

Make sure you really understand the OSGi model with services. You might want to take a look at OSGi enRoute that leverages OSGi to the hilt.

I propose you take a look at the blueprint-maven-plugin . It allows to use a subset of CDI and JEE annoations to define injections as well as transactions and persistence. The plugin creates blueprint xml at build time which can then be executed by karaf. The big advantage is that these annotations are also supported by spring. So you can transition and in parallel release to production using spring.

I have a complete example here Annotation based blueprint and JPA .

Using this plugin I migrated a medium sized project while it was developed and released in parallel. If you need further advice while using the plugin I can surely help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM