Spring机制类似于OSGI/Eclipse扩展点
我们编写了一个在底层使用 spring 的框架。该框架由两个应用程序使用。可以配置生产服务器来运行 application1 OR application2 OR application1 和 application2。
现在我正在寻找一种类似于 OSGI 扩展点思想的 spring 机制,以便每个应用程序都可以“贡献”到框架,而无需列出所有应用程序的配置文件。
完整的项目结构(简化;-)):
框架:A、IPlugin、A.xml
应用程序 1:B 扩展 IPlugin、b.xml
应用程序 2:C 扩展 IPlugin、c.xml
说明: “A”使用 IPllugin 列表,如果必须完成特定任务,将调用该列表。
我只找到了将 A 声明为原型并将“B”和“C”设置为属性的 spring 方法。因此我必须在 A.xml 中明确列出两者。但我想在 b.xml 和 c.xml 中配置贡献。
问题:
如果创建了特殊类型的bean的实例,spring中是否有可能被修改?
spring 中是否有类似 OSGI/Eclipse 扩展点的开箱即用的东西?
还有其他建议吗?
We wrote a framework which uses spring under the hood. This framework is used by two applications. It is possible to configure a production server with running application1 OR application2 OR application1 and application2.
Now I am looking for a spring mechanism which works similar to OSGI Extension-point idea, so that each application can "contribute" to framework without a configuration file where all applications need to be listed.
Complete project-structure (simplified ;-)):
Framework: A, IPlugin, A.xml
Application 1: B extends IPlugin, b.xml
Application 2: C extends IPlugin, c.xml
Explenation:
"A" uses a list of IPllugin which will be called if a specific task has to be achieved.
I only found the spring way of declaring A as prototyp and setting "B" and "C" as attributes. Therefore I have to list both explicitly in A.xml. But I want to configure contributions in b.xml and c.xml.
Questions:
Is there a possibility in spring to be modified if an instance of a special kind of bean is created?
Is there something similar to OSGI/Eclipse extension-point in spring out of the box?
Any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 Spring 动态模块。简介的第一行说明了一切:
Take a look at Spring Dynamic Modules. The first line of the introduction says it all:
其他人建议将 OSGi 与 Spring-DM 或 Blueprint 一起使用。如果您决定这就是您想要做的 - 我自己也不确定,因为我没有完全理解问题描述 - 那么您应该能够将 OSGi 框架嵌入到您现有的应用程序中(是的,甚至在 Tomcat 中...)。
我写了一篇关于如何嵌入 OSGi 的博客文章,它可能会帮助您开始吧。但首先要检查 OSGi 与 Spring-DM 是否真的是您想要的,如果您需要帮助做出决定,请提出后续问题。
Others have suggested using OSGi with Spring-DM or Blueprint. If you decide that's what you want to do -- and I'm not sure about that myself because I didn't entirely understand the problem description -- then you should be able to embed an OSGi framework into your existing application (yes, even inside Tomcat...).
I wrote a blog post on how to embed OSGi that might help you to get started. But check out first whether OSGi with Spring-DM is really what you want, and do ask follow up questions if you need help making that decision.
我的解决方案是在框架项目中创建一个“注册表”,该项目将在春季创建,范围为“singleton”。因此每个插件都可以对该注册表做出贡献,因为它在应用程序服务器运行时可供所有插件使用。由于每个插件都应该是新创建的,所以我使用了工厂的帮助,该工厂从 spring-context 创建新的插件实例。
更多细节可以在我写的一篇小文章中找到,可以下载
My solution was to create a "registry" in the framework project which will be created in spring with scope "singleton". So each plugin can contribute to this registry because it is available to all plugins during runtime of the application server. Since each plugin should be created new I used the help of a factory which creates new plugin-instances from spring-context.
More details can be found in a small article I wrote and which can be downloaded