<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=kdonald" rel="nofollow">Keith Donald</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7973?redirect=false" rel="nofollow">SPR-7973</a></strong> and commented</p>
<p dir="auto">I found the following odd with <code class="notranslate">@ImportResource</code> usage:</p>
<ol dir="auto">
<li>
<p dir="auto">The <code class="notranslate">@ImportResource</code> ResourceLoader does not appear to be the same ResourceLoader as the ApplicationContext.  I am using a AnnotationConfigWebApplicationContext, and I got classpath-relative resources by default.</p>
</li>
<li>
<p dir="auto">Configuration-class relative resource resolution does not work, and one might expect it to.  For example, if I import <code class="notranslate">@ImportResource</code>("mvc-interceptors.xml") from the com.springsource.greenhouse.config.mvc package, I'd expect "mvc-interceptors.xml" to be in that package, and not the root of the classpath.  Having to specify "com/springsource/greenhouse/config/mvc/mvc-interceptors.xml" is a lot more to type and feels strange.</p>
</li>
</ol>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/17723/mylyn-context.zip" rel="nofollow">mylyn-context.zip</a> (<em>26.03 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398110254" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12630" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12630/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12630">#12630</a> Dependency injection not supported on <code class="notranslate">@FeatureConfiguration</code> classes</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/4cdb04ab25a91043ef51d52c916ef2684e98174b/hovercard" href="https://github.com/spring-projects/spring-framework/commit/4cdb04ab25a91043ef51d52c916ef2684e98174b"><tt>4cdb04a</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cbeams" rel="nofollow">Chris Beams</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6310?redirect=false" rel="nofollow">SPR-6310</a></strong> and commented</p>
<p dir="auto">Much like Spring's TestContext framework and its <code class="notranslate">@ContextConfiguration</code> annotation, processing <code class="notranslate">@Configuration</code> classes should support relative paths and loading resources by convention when using <code class="notranslate">@ImportXml</code>:</p>
<ol dir="auto">
<li>Relative paths:</li>
</ol>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package com.biz.app;
@Configuration
@ImportResource(&quot;Foo.xml&quot;)
public class AppConfig { ... }"><pre class="notranslate"><span class="pl-k">package</span> <span class="pl-s1">com</span>.<span class="pl-s1">biz</span>.<span class="pl-s1">app</span>;
<span class="pl-c1">@</span><span class="pl-c1">Configuration</span>
<span class="pl-c1">@</span><span class="pl-c1">ImportResource</span>(<span class="pl-s">"Foo.xml"</span>)
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">AppConfig</span> { ... }</pre></div>
<p dir="auto">It is assumed that Foo.xml resides in <code class="notranslate">com.biz.app</code>, the same package in which <code class="notranslate">AppConfig</code> is declared.</p>
<ol dir="auto">
<li>Import by convention:</li>
</ol>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package com.biz.app;
@Configuration
@ImportResource
public class AppConfig { ... }"><pre class="notranslate"><span class="pl-k">package</span> <span class="pl-s1">com</span>.<span class="pl-s1">biz</span>.<span class="pl-s1">app</span>;
<span class="pl-c1">@</span><span class="pl-c1">Configuration</span>
<span class="pl-c1">@</span><span class="pl-c1">ImportResource</span>
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">AppConfig</span> { ... }</pre></div>
<p dir="auto">It is assumed that <code class="notranslate">classpath:/com/biz/app/AppConfig-context.xml</code> exists.</p>
<p dir="auto">See <code class="notranslate">testImportXmlWithRelativePath()</code> and <code class="notranslate">testImportXmlByConvention()</code>, which are both currently <code class="notranslate">@Ignore</code>'d in <code class="notranslate">org.springframework.context.annotation.configuration.ImportXmlTests</code>.  See also TODO in <code class="notranslate">ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromXml()</code></p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398097769" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10826" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10826/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10826">#10826</a> Support <code class="notranslate">@ImportResource</code> within <code class="notranslate">@Configuration</code> classes (<em><strong>"depends on"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112416" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13003" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13003/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13003">#13003</a> Relative imports in <code class="notranslate">@Configuration</code> classes</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398099038" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10993" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10993/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10993">#10993</a> Preserve 'reader' attribute in <code class="notranslate">@ImportResource</code> hierarchies</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/ae11387b4aa628c0834198c45cf733b6cd23f71d/hovercard" href="https://github.com/spring-projects/spring-framework/commit/ae11387b4aa628c0834198c45cf733b6cd23f71d"><tt>ae11387</tt></a></p>
<p dir="auto">1 votes, 3 watchers</p>