title: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: AnnotationConfigApplicationContext
body: <p>I have two configuration files with same bean definition with different @Qualifier as follows. and want to those two beans in my application.to avoid the bean definition overriding in spring boot i used ApplicationContextInitializer and got the below exception.</p>
  
  <h2>first configuration</h2>
  
  <pre><code>@Bean(destroyMethod = "shutdown")
      @Qualifier("batchAmazonSQSAsync")
      public AmazonSQSAsync amazonSQS(@Qualifier("batchClientConfiguration") ClientConfiguration clientConfiguration,
              @Qualifier("batchAWSCredentialsProviderChain") AWSCredentialsProviderChain credentialsProviderChain) {
  
  
  
          AmazonSQSAsync amazonSQSAsyncClient = AmazonSQSAsyncClientBuilder.standard()
                  .withClientConfiguration(clientConfiguration).withCredentials(credentialsProviderChain)
                  .withRegion(Regions.fromName(region)).build();
          return new AmazonSQSBufferedAsyncClient(amazonSQSAsyncClient);
      }
  
      @Bean
      @Qualifier("batchClientConfiguration")
      ClientConfiguration clientConfiguration() {     
          ClientConfiguration clientConfiguration = new ClientConfiguration();
          clientConfiguration.setProxyHost(proxyHost);
          clientConfiguration.setProxyPort(proxyHostPort);
          clientConfiguration.setProxyUsername(proxyUserName);
          clientConfiguration.setProxyPassword(proxyPassword);
          return clientConfiguration;
      }
  
      @Bean
      @Qualifier("batchAWSCredentialsProviderChain")
      AWSCredentialsProviderChain credentialsProviderChain() {
  
          return new AWSCredentialsProviderChain(
                  new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
      }
  </code></pre>
  
  <h2>second configuration</h2>
  
  <pre><code>@Bean(destroyMethod = "shutdown")
      @Qualifier("priorityAmazonSQSAsync")
      public AmazonSQSAsync amazonSQS(@Qualifier("priorityClientConfiguration") ClientConfiguration clientConfiguration,
              @Qualifier("priorityAWSCredentialsProviderChain") AWSCredentialsProviderChain credentialsProviderChain) {       
  
          AmazonSQSAsync amazonSQSAsyncClient = AmazonSQSAsyncClientBuilder.standard()
                  .withClientConfiguration(clientConfiguration).withCredentials(credentialsProviderChain)
                  .withRegion(Regions.fromName(region)).build();
          return new AmazonSQSBufferedAsyncClient(amazonSQSAsyncClient);
      }
  
      @Bean
      @Qualifier("priorityClientConfiguration")
      ClientConfiguration clientConfiguration() { 
  
          ClientConfiguration clientConfiguration = new ClientConfiguration();
          clientConfiguration.setProxyHost(proxyHost);
          clientConfiguration.setProxyPort(proxyHostPort);
          clientConfiguration.setProxyUsername(proxyUserName);
          clientConfiguration.setProxyPassword(proxyPassword);
          return clientConfiguration;
      }
  
      @Bean
      @Qualifier("priorityAWSCredentialsProviderChain")
      AWSCredentialsProviderChain credentialsProviderChain() {    
  
          return new AWSCredentialsProviderChain(
                  new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
      }
  </code></pre>
  
  <h2>spring boot application</h2>
  
  <pre><code>public static void main(String[] args) {
  
          ConfigurableApplicationContext ctx = new SpringApplicationBuilder(SqslistenerApplication.class)
                  .initializers(new ApplicationContextInitializer&lt;GenericApplicationContext&gt;() {
                      @Override
                      public void initialize(GenericApplicationContext applicationContext) {
                          applicationContext.setAllowBeanDefinitionOverriding(false);
                      }
                  }).run(args);
          ctx.refresh();
  
          // SpringApplication.run(SqslistenerApplication.class, args);
  
      }
  </code></pre>
  
  <h2>exception while running the application</h2>
  
  <pre><code>java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@e056f20: startup date [Wed Nov 08 13:06:32 IST 2017]; root of context hierarchy
      at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:556) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at demo.sqs.SqslistenerApplication.main(SqslistenerApplication.java:20) [classes/:na
  </code></pre>
  
  <p>]</p>
  
  <h2>pom.xml</h2>
  
  <p>
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
      4.0.0</p>
  
  <pre><code>&lt;groupId&gt;demo.sqs&lt;/groupId&gt;
  &lt;artifactId&gt;sqslistener&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  
  &lt;name&gt;sqslistener&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.6.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
              &lt;version&gt;Dalston.SR4&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-aws-messaging&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>