2011-06-12 120 views
1

我想在osgi(fuse esb)中部署一個基於spring的包。在spring上下文中,我指的是資源文件夾內的db4o文件。根據我的理解,Maven項目將確保在資源文件夾下可用的任何文件將在項目類路徑中可用。我已將該文件保存在資源/ META-INF/spring/repo/test.db4o下。春季OSGi類路徑資源問題

下面是春天的條目。


<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似乎沒有認出這個文件。任何指針將不勝感激。

-Thanks

+0

捆綁'test.db4o'文件在哪?你必須把它們放在同一個包中。 – 2011-06-13 02:33:06

+0

它在同一個包中。 – Shamik 2011-06-13 15:09:12

+0

您是否嘗試過'classpath:/ META-INF/spring/repo/test.db4o'(路徑以斜線開頭) – FrVaBe 2011-06-14 09:11:24

回答

0

我終於找到了問題。 ObjectContainerFactoryBean依靠OSGiResourceBundle將資源加載爲文件對象。儘管OSGiResourceBundle公開了一種名爲getFile()的方法,但它在OSGi環境中無法正常工作。它總是期望一個文件協議,而作爲URI返回的資源具有協議「捆綁」。因此,拋出異常。解決方法是使用inputstream或getUrl。由於我沒有ObjectContainerFactoryBean的源代碼,我不得不擴展這個類來提供我自己的實現,它將文件加載爲輸入流。