Spring @EnableAsync breaks bean initialization order?
<p>I wanted to introduce <code>@Async</code> methods (for sending mails in parallel) in my SpringBoot application.
But when I put the <code>@EnableAsync</code> annotation on our application's main <code>@Configuration</code> class (annotated with <code>@SpringBootApplication</code>), the Flyway DB migrations are executed before the <code>DataSourceInitializer</code> (which runs schema.sql and data.sql for my tests) executed.</p>

<p>The first operation involving a 'should-be-migrated' database table fails.</p>

<p>Removing the <code>@EnableAsync</code> puts everything back to normal. Why does this happen and how could I fix this (or work around the issue)?</p>

<p><strong>Update</strong> Some more findings: <code>@EnableAsync(mode = AdviceMode.ASPECTJ)</code> keeps the original order of DB setup, but the <code>@Async</code> method runs on the same thread as caller thread then. I also saw that the Bean 'objectPostProcessor' is created early (3rd bean) when <code>@EnableAsync</code> is not present, or <code>@EnableAsync(mode = AdviceMode.ASPECTJ)</code> is used. When only <code>@EnableAsync</code> is used, this bean is created much later.</p>

<p><strong>Update 2</strong> While I wasn't able to create a minimal project which reproduces the problem yet, I found out that the proper DB setup order is restored in my affected application when I comment out the <code>@EnableWebSocketMessageBroker</code> in the following:</p>

<pre><code>@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer
{ 
  ...
}
</code></pre>

<p>Bean 'webSocketConfig' is the first bean created (as per INFO-level console output) if <code>@EnableWebSocketMessageBroker</code> is present.</p>