简体   繁体   English

从Spring Monolith应用程序迁移到OSGI

[英]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. 在过去的十年中,我们一直在使用Spring作为依赖注入来构建两个应用程序套件。 We also use spring-batch and spring-amqp. 我们还使用spring-batch和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. 现在,我们正在寻求迁移到OSGI,以便将我们的整体应用程序分成多个包,从而使我们更加敏捷。 The two suites are web applications and are deployed as two separate war files. 这两个套件是Web应用程序,被部署为两个单独的war文件。 We are looking to use Apache Karaf as our OSGI runtime. 我们希望将Apache Karaf用作我们的OSGI运行时。

Spring-DM is dead and it appears that we are going to have to convert EVERYTHING to use Blueprint for our dependency injection. Spring-DM已经死了,看来我们将不得不转换一切以使用Blueprint进行依赖注入。

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. 似乎一个捆绑包仍然应该能够使用Spring DI并拥有自己的应用程序上下文,只要我们有责任向捆绑包激活器中的服务注册表公开我们想要的任何服务,但是我不确定是否有就像交易管理一样,这是我们会失去的魔力。

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. 您可能要考虑使问题看起来更大,并改用DS而不是Blueprint ...为了真正利用OSGi模型,DS在所有方面都远远优于Blueprint。 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. 尽管Blueprint使Spring可以在OSGi上使用,但它从未“脱颖而出” OSGi。

For strategy, keep your Spring app alive as a single bundle and move things out gradually. 对于策略,请让您的Spring应用程序作为一个捆绑包保持活动状态,然后逐步将其移出。 Ie the elephant approach. 即大象的方法。

The biggest gain that OSGi provides can be summarized as follows: OSGi提供的最大收益可总结如下:

  • Make sure modules have service APIs that ONLY handle collaboration. 确保模块具有仅处理协作的服务API。 Ie each service API should be a story/scenario how the actors work together, not how they come into existence and are configured. 也就是说,每个服务API都应该是一个故事/场景,参与者是如何协同工作的,而不是他们如何形成和配置的。
  • Let Configuration Admin to the configuration work. 让Configuration Admin进行配置。 Ie never expose configuration APIs. 即从不公开配置API。 In OSGi, you register instances, not things that still need to be configured. 在OSGi中,您注册的是实例,而不是仍需要配置的东西。

Make sure you really understand the OSGi model with services. 确保您真的了解带有服务的OSGi模型。 You might want to take a look at OSGi enRoute that leverages OSGi to the hilt. 您可能想看看利用OSGi的OSGi enRoute

I propose you take a look at the blueprint-maven-plugin . 我建议您看看blueprint-maven-plugin It allows to use a subset of CDI and JEE annoations to define injections as well as transactions and persistence. 它允许使用CDI和JEE注释的子集来定义注入以及事务和持久性。 The plugin creates blueprint xml at build time which can then be executed by karaf. 该插件在构建时创建蓝图xml,然后可由karaf执行。 The big advantage is that these annotations are also supported by spring. 最大的好处是spring也支持这些注释。 So you can transition and in parallel release to production using spring. 因此,您可以使用spring过渡并并行发布到生产环境。

I have a complete example here Annotation based blueprint and JPA . 我在这里有一个完整的基于注释的蓝图和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. 如果您在使用插件时需要更多建议,我一定会提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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