<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=yozh" rel="nofollow">Stepan Koltsov</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8719?redirect=false" rel="nofollow">SPR-8719</a></strong> and commented</p>
<p dir="auto"><code class="notranslate">@ComponentScan</code> does not work in <code class="notranslate">@Import-ed</code> configuration.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class Coin { }

public class Main {

    @Configuration
    @ComponentScan(basePackageClasses = Main.class,
            useDefaultFilters = false,
            includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Coin.class))
    public static class Conf1 {
    }

    @Configuration
    @Import(Conf1.class)
    public static class Conf2 {

    }

    public static void main(String[] args) {
        System.out.println(&quot;loading Conf1&quot;); // works fine
        new AnnotationConfigApplicationContext(Conf1.class).getBean(Coin.class);

        System.out.println(&quot;loading Conf2&quot;); // cannot find a bean
        new AnnotationConfigApplicationContext(Conf2.class).getBean(Coin.class);
        System.out.println(&quot;Unreachable in Spring 3.1.0.M2&quot;);
    }

}"><pre class="notranslate"><code class="notranslate">public class Coin { }

public class Main {

    @Configuration
    @ComponentScan(basePackageClasses = Main.class,
            useDefaultFilters = false,
            includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Coin.class))
    public static class Conf1 {
    }

    @Configuration
    @Import(Conf1.class)
    public static class Conf2 {

    }

    public static void main(String[] args) {
        System.out.println("loading Conf1"); // works fine
        new AnnotationConfigApplicationContext(Conf1.class).getBean(Coin.class);

        System.out.println("loading Conf2"); // cannot find a bean
        new AnnotationConfigApplicationContext(Conf2.class).getBean(Coin.class);
        System.out.println("Unreachable in Spring 3.1.0.M2");
    }

}
</code></pre></div>
<p dir="auto">Outputs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="loading Conf1
loading Conf2
Exception in thread &quot;main&quot; org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [ru.yandex.commune.junk.stepancheg.spring.shinderuk.Coin] is defined: expected single bean but found 0: 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:269)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1101)
	at ru.yandex.commune.junk.stepancheg.spring.shinderuk.Main.main(Main.java:31)"><pre class="notranslate"><code class="notranslate">loading Conf1
loading Conf2
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [ru.yandex.commune.junk.stepancheg.spring.shinderuk.Coin] is defined: expected single bean but found 0: 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:269)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1101)
	at ru.yandex.commune.junk.stepancheg.spring.shinderuk.Main.main(Main.java:31)
</code></pre></div>
<p dir="auto">Probably related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112157" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12956" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12956/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12956">#12956</a>.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M2</p>
<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="398116710" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13670" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13670/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13670">#13670</a> <code class="notranslate">@ComponentScan</code> with includeFilters on <code class="notranslate">@Import-ed</code> context does not work (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398110272" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12634" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12634/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12634">#12634</a> <code class="notranslate">@ComponentScan</code> does not work when referenced from XML config (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117136" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13738" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13738/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13738">#13738</a> ClassPathBeanDefinitionScanner vs ClassPathBeanDefinitionScanner: difference in behavior when dealing with <code class="notranslate">@ComponentScan</code> excludeFilters</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/d9f7fdd120409fff4491561215e5b2dda74e2b02/hovercard" href="https://github.com/spring-projects/spring-framework/commit/d9f7fdd120409fff4491561215e5b2dda74e2b02"><tt>d9f7fdd</tt></a></p>
<p dir="auto">2 votes, 0 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=superpuma" rel="nofollow">Jon Are Storløkken</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2877?redirect=false" rel="nofollow">SPR-2877</a></strong> and commented</p>
<p dir="auto">This is mainly a documentation issue. (Although it would be possible to improve on the design as well)</p>
<p dir="auto">The problem is the org.springframework.scheduling.quartz.JobDetailBean. It should be clearly stated that this bean cannot be used with a persistent job store. This is such an important issue when using Quartz, that it should be mentioned explicitly. Among other things, a persistent job store is required when running Quartz in a cluster. This is a very common requirement in enterprise applications, and JobDetailBean is therefore not very useful for most applications.</p>
<p dir="auto">My problem actually stems from using code copied from the book ProSpring (p 513) by Rob Harrop, where he shows an example of using JobDetailBean with a persistent job store. Clearly, this config has never been tested. This is a widely read book (by an Interface21 guy AFAIK), and this config will be widely read and copied.</p>
<p dir="auto">In my opinion the code could be improved:<br>
The problem stems from JobDetail bean being ApplicationContextAware, which it needn't be. (It puts the applicationContext in the jobDataMap) SchedulerFactory puts the applicationContext in the schedulerContext anyway, why can not the Job get the applicationContext from there?</p>
<p dir="auto">See this thread for some further info:<br>
<a href="http://forum.springframework.org/showthread.php?t=31820" rel="nofollow">http://forum.springframework.org/showthread.php?t=31820</a></p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.2.8, 2.0.1</p>
<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="398072964" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7537" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7537/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7537">#7537</a> Upgrade to Quartz 1.6.1 (for trigger persistence with SimpleTriggerBean and CronTriggerBean) (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 1 watchers</p>