Spring OSGi类路径资源问题

发布于 2024-11-15 03:03:09 字数 820 浏览 7 评论 0原文

我正在尝试在 osgi (fuse esb)中部署基于 spring 的包。在 spring 上下文中,我指的是 resources 文件夹内的 db4o 文件。根据我的理解,maven 项目将确保资源文件夹下的任何可用文件都将在项目类路径中可用。我将该文件保存在 resources/META-INF/spring/repo/test.db4o 下。

这是 spring 上下文中的条目。


<bean id="objectContainer" class="org.springmodules.db4o.ObjectContainerFactoryBean">
    <property name="databaseFile" value="classpath:META-INF/spring/repo/test.db4o" />
</bean>

一旦我安装并尝试启动该应用程序,我就会收到以下异常。


java.io.FileNotFoundException: OSGi resource[classpath:META-INF/spring/repo/test.db4o|bnd.id=258|bnd.sym=taxonomydaoimplbundle] cannot be resolved to absolute file path because it does not reside in the file system: bundle://258.0:1/META-INF/spring/repo/test.db4o

我尝试了不同的组合,但 OSGi 似乎无法识别该文件。任何指针将不胜感激。

-谢谢

I'm trying to deploy a spring based bundle in osgi (fuse esb).In spring context, I'm referring to a db4o file which is inside resources folder. As per my understanding, a maven project will make sure that any file available under resources folder will be available in project classpath. I've kept the file under resources/META-INF/spring/repo/test.db4o.

Here's the entry in spring context.


<bean id="objectContainer" class="org.springmodules.db4o.ObjectContainerFactoryBean">
    <property name="databaseFile" value="classpath:META-INF/spring/repo/test.db4o" />
</bean>

Once I install and try to start the application, I'm getting the following exception.


java.io.FileNotFoundException: OSGi resource[classpath:META-INF/spring/repo/test.db4o|bnd.id=258|bnd.sym=taxonomydaoimplbundle] cannot be resolved to absolute file path because it does not reside in the file system: bundle://258.0:1/META-INF/spring/repo/test.db4o

I've tried different combinations, but OSGi doesn't seem to recognize this file. Any pointer will be appreciated.

-Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2024-11-22 03:03:09

我终于找到问题了。 ObjectContainerFactoryBean 依赖 OSGiResourceBundle 将资源作为文件对象加载。尽管 OSGiResourceBundle 公开了一个名为 getFile() 的方法,但它在 OSGi 环境中无法按预期工作。它始终需要文件协议,而作为 URI 返回的资源具有协议“包”。因此,会引发异常。解决方法是使用 inputstream 或 getUrl。由于我没有 ObjectContainerFactoryBean 的源代码,因此我必须扩展此类以提供我自己的实现,该实现将文件作为输入流加载。

I found the issue finally. ObjectContainerFactoryBean is relying on OSGiResourceBundle to load the resource as a file object. Though OSGiResourceBundle exposes a method called getFile(), it doesn't work as intended in an OSGi environment. It always expects a file protocol whereas the resource returned as an URI has a protocol "bundle".Hence, the exception is being thrown. The workaround is to use a inputstream or getUrl. Since I didn't have the source code of ObjectContainerFactoryBean, I had to extend this class to provide my own implementation which loads the file as an inputstream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文