OSGi捆绑软件从另一个捆绑软件访问Spring上下文文件 [英] OSGi bundle access Spring context file from another bundle

查看:89
本文介绍了OSGi捆绑软件从另一个捆绑软件访问Spring上下文文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存在于多个Spring项目中的现有应用程序.项目A的Spring上下文XML文件使用

I have an existing application that exists as multiple Spring projects. Project A's Spring context XML file improts B's Spring context XML file using

<import resource="classpath*:/META-INF/spring/BContext.xml" />

但是,我得到一个FileNotFoundException.我认为这是由于项目B的捆绑包未公开该资源引起的.我可以访问这些类,但不能访问该文件.

However, it I get a FileNotFoundException. I assume this is caused by the fact that the resource is not exposed by project B's bundle. I can access the classes, but not the file.

研究此问题时,常见的评论是使用OSGi服务并注入服务,而不是尝试直接注入bean.但是,由于这是一个现有应用程序,因此我想避免重新连接整个内容.

When researching this issue the common comment was to use OSGi services and inject the services instead of trying to inject the beans directly. However, since this is an existing application, I would like to avoid rewiring the entire thing.

有什么办法告诉OSGi导出资源吗?我在Karaf上运行ServiceMix.

Is there any way to tell OSGi to export the resource? I'm running ServiceMix on Karaf.

推荐答案

这只是类路径资源,因此我假设添加适当的Export-Package指令即可解决问题.不过,那绝对不是正确的方法.该上下文文件的路径表明,也许已经将包含BContext.xml的项目设置为可与Spring Dynamic Modules一起使用.如果是这样,那么当您启动该捆绑包时,Spring ApplicationContext将作为服务导出.在OSGi控制台中查找它.

It's just a classpath resource, so I would assume adding an appropriate Export-Package directive would do the trick. That's definitely not the right way to do it, though. The path of that context file suggests that perhaps the project that contains BContext.xml is already set up to work with Spring Dynamic Modules. If so, then when you start that bundle, the Spring ApplicationContext is exported as a service. Look for it in your OSGi console.

针对评论中的讨论:

我从没有尝试过,但是从理论上讲,应该可以使用Spring DM的 of

I've never tried this myself, but theoretically it should be possible to use Spring DM's osgi namespace to make a bean reference to the OSGi service which is project B's ApplicationContext. Then, having a bean which is the ApplicationContext, you can use normal Spring configuration to extract beans from it using one of the getBean() methods. Note that you can use <constructor-arg ... /> to specify arguments to a factory method in a Spring config, as shown toward the bottom of this examples section.

这篇关于OSGi捆绑软件从另一个捆绑软件访问Spring上下文文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆