开发者

Spring config to load resources within bundle

开发者 https://www.devze.com 2023-01-27 04:06 出处:网络
I have an war osgi bundle th开发者_如何学Goat I have created from a legacy web application.The problem I have is that in the spring configuration there are references to files that reside on the class

I have an war osgi bundle th开发者_如何学Goat I have created from a legacy web application. The problem I have is that in the spring configuration there are references to files that reside on the classpath (see below) which are fine when the legacy war was deployed to tomcat as they could be found on thr filesystem. However, as osgi has no concept of a file system then these files cannot be located and I get a file not found exception. can anyone please tel me if I can continue to load classpth resources in this or a similar way. Or do I have to load them programmaticlly using the org.springframework.osgi.io.OsgiBundleResource for exmple.

<bean id="manager" class="com.xyz.abc.Manager" depends-on="workflowCache">
    <property name="configuration" value="classpath:com/xyz/abc/resource/workflow.xml"/>
</bean>

Thanks in advance.


The problem here is almost certainly not that OSGi does not have the concept of a file system, but that the file isn't on the classpath anymore.

I assume that when the war runs in normal tomcat the workflow.xml you reference is on the file system and accessible via the tomcat classpath. The classloader for the WAR delegates to the parent classloader, which is able to access the workflow.xml file.

In OSGi your classpath is defined by the Bundle-Classpath and any package imports, or bundle requirements. This workflow.xml file is obviously not accessible via any of these mechanisms.

There are a few options:

  1. Put the workflow.xml inside the bundle and put it on the Bundle-Classpath. This isn't so good if you want the file to be editable without rebuilding the WAB.
  2. When launching the OSGi framework add the workflow.xml file onto the classpath. Then as a framework launch option set org.osgi.framework.bootdelegation to be com.xyz.abc.resource. Note that if you do this you will no longer be able to load com.xyz.abc.resource from within the OSGi framework, it will always load them from the frameworks parent classloader
  3. If you are using equinox you can put external files on the bundle classpath by adding external: to the front of a file path in the Bundle-Classpath. It is somewhat artificial though as your bundle is unlikely to work elsewhere.

These are all a little (a lot) hacky, so you might wish to look at different way to load this file. I'm not familiar with the OsgiBundleResource though.

If you are running in OSGi you might wish to take a look at the Blueprint Container specification which was based on Spring DM. There are two implementations I know of, Apache Aries, and Eclipse Gemini.


Guys, I had the similar problem. So I tried this (changed classpath -> file)

It worked, though it does not seems to be a logical reason, because the file was on the classpath and equinox was not able to find it using classpath: but did find the file using file:

Till any logical reason is found, we can go ahead an use this, if it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消