<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Problems with Spring resource loading in an OSGi bundle
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/tpesce">Tim Pesce</a> in <i>Snowdrop</i> - <a href="http://community.jboss.org/message/632884#632884">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I have a large Spring application that I am trying to convert to a single OSGi bundle for deployment into JBoss (AS 7.0.2). Initially I am trying to minimize code changes and deploy the application as-is, but I am running into issues with Spring resource loading. I've created a relatively simple application as a reproducer. The application is an OSGi bundle with a few simple Spring beans using ClassPathXmlApplicationContext. I am building the bundle with maven-bundle-plugin and embeding transitive dependencies including Spring 3.0.6 JARs.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When I use a simple configuration location such as "classpath:spring/applicationContext.xml" everything works fine. However, the real application has several different locations using combinations of "classpath*:" and location patterns such as "classpath:spring/*Context.xml". These locations with patterns are causing problems.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Despite Spring's support for VFS it is not being used in these cases. Within the OSGi context Spring is getting resource URLs with a "bundle:" protocol and doesn't know what to do with them. So it falls back to assuming they are files, and the resource loading fails:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
22:05:18,264 WARN&#160; [org.springframework.core.io.support.PathMatchingResourcePatternResolver] (MSC service thread 1-4) Cannot search for matching files underneath class path resource [spring/] because it does not correspond to a directory in the file system: java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to absolute file path because it does not reside in the file system: bundle://com.tendril.test.spring.osgi-23-0-0/spring/
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>After some research I found Snowdrop and am hoping it can help. I am embedding snowdrop-vfs 2.0.0.Final in my bundle, I have switched to using VFSClassPathXmlApplicationContext, and I have configured OSGi to use these VFS modules:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
&lt;module identifier="org.jboss.vfs"/&gt;
&lt;module identifier="org.jboss.osgi.vfs" startlevel="1"/&gt;</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>However, using a location with patterns such as "classpath:spring/*Context.xml" does not seem to work; none of my beans are found:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
22:19:35,672 INFO&#160; [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-1) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@8a70e3a: defining beans []; root of factory hierarchy
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Interestingly, using a patternless location that works with ClassPathXmlApplicationContext (classpath:spring/applicationContext.xml) does not work with VFSClassPathXmlApplicationContext:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
Caused by: java.io.FileNotFoundException: /spring/applicationContext.xml (No such file or directory)
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at java.io.FileInputStream.open(Native Method) [:1.6.0_26]
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:120) [:1.6.0_26]
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at org.jboss.vfs.spi.RootFileSystem.openInputStream(RootFileSystem.java:55)
&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at org.jboss.vfs.VirtualFile.openStream(VirtualFile.java:238) [jboss-vfs-3.0.1.GA.jar:3.0.1.GA]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/632884#632884">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Snowdrop at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2082">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>