title: Spring does not abort bootstrapping on bean initialization Error when component scanning is enabled?
body: <p>I have a web application with a spring configuration file. I have the following entry:</p>
  
  <pre><code>&lt;bean id="flyway" class="xxx.FlywayTool" init-method="migrateOrFail"/&gt;
  </code></pre>
  
  <p>The "flyway" bean is used to initialize and migrate the database.Now I have another bean defining the datasource the application should use:</p>
  
  <pre><code>&lt;bean id="dataSource" class="..." depends-on="flyway"&gt;
  </code></pre>
  
  <p>this one depends on flyway to succeed.</p>
  
  <p>Everything is working fine. Now, when the "flyway" bean throws an exception the bootstrapping of spring stops and the webapp startup is finished - all good.</p>
  
  <p>Now i am starting to enable autowiring for certain components via:</p>
  
  <pre><code>&lt;context:component-scan base-package="de.xxxxx.xxxxx" /&gt;
  </code></pre>
  
  <p>in some of the classes I depend on services which are also defined as beans in the xml configuration. and they I turn depend on the datasource mentioned above.</p>
  
  <p>now the problem: as soon as I bootstrap the application now and "flyway" is throwing an exception the exception is swallowed by spring in the following section:</p>
  
  <p><em>org.springframework.beans.factory.support.AbstractBeanFactory.getTypeForFactoryBean(String, RootBeanDefinition)</em></p>
  
  <pre><code>catch (BeanCreationException ex) {
     // Can only happen when getting a FactoryBean.
     if (logger.isDebugEnabled()) {
         logger.debug("Ignoring bean creation exception on FactoryBean type check: " + ex);
     }
     onSuppressedException(ex);
     return null;
  }
  </code></pre>
  
  <p>and now spring tries, for every other dependend service (that depends on the datasource and therefore flyway) initialize all the beans which in turn results in the same procedure again and again.</p>
  
  <p>This exceptional loop continues until spring is finished trying to instaniate every possible dependency instead of aborting after the first flyway error.</p>
  
  <p>This strange behaviour only starts when I enable component scanning via</p>
  
  <pre><code>&lt;context:component-scan ....
  </code></pre>
  
  <p>when this feature is disabled spring stops after the first flyway error happend. It also ends up in another class:</p>
  
  <p><em>org.springframework.context.support.AbstractApplicationContext.refresh()</em></p>
  
  <pre><code>        catch (BeansException ex) {
              // Destroy already created singletons to avoid dangling resources.
              destroyBeans();
  
              // Reset 'active' flag.
              cancelRefresh(ex);
  
              // Propagate exception to caller.
              throw ex;
          }
  </code></pre>
  
  <p>so this is the behaviour i would expect in the other case too.</p>
  
  <p>our spring version: <strong>3.0.6.RELEASE</strong></p>
  
  <p>this behaviour is also present with other classes throwing any runtime execption (not just flyway) is this a bug or expected behaviour?</p>
  
  <p>any help highly appreciated</p>
  
  <p>marcel</p>