title: Failed to Stop Bean during server shutdown
body: <p>I have a war file that utilizes spring and stomp messages. Everything works great but during shutdown or restart I see hundreds of lines like:</p>
  
  <pre><code>07-Feb-2018 12:21:35.929 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.929 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.929 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.929 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.929 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.930 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.930 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.930 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.930 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.930 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.931 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.931 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.931 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.931 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.931 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.932 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.932 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.932 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.932 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.933 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:35.933 [INFO ] Stopping beans in phase 0
  07-Feb-2018 12:21:35.933 [INFO ] Stopping beans in phase 2147483647
  07-Feb-2018 12:21:36.394 [WARN ] Failed to stop bean 'accountEventPublisher'
  java.lang.StackOverflowError: null
  </code></pre>
  
  <p>My accountEventPublisher bean publishes events to allow other parts of the server to intercept the event and act on it.</p>
  
  <p>This is my accountEventPublisherBean:</p>
  
  <pre><code>@Configuration
  public class AccountEventPublisherConfig {
  
    public static final String MULTICAST_NAME = "accountEventMulticaster";
  
    public static final String EVENT_PUBLISHER_NAME ="accountEventPublisher";
  
    @Autowired 
    private ApplicationEventPublisher publisher;
  
    @Bean(name=MULTICAST_NAME)
    public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
      SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
      eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
      return eventMulticaster;
    }
  
    @Bean(name=EVENT_PUBLISHER_NAME)
    public ApplicationEventPublisher simplePublisher() {
      return publisher;
    }
  }
  </code></pre>
  
  <p>I then use it in my static CommService to send events:</p>
  
  <pre><code>@Service
  public class CommService {
    private static ApplicationEventPublisher accountEventPublisher;
  
    public static void sendEvent(ApplicationEvent event) {
      if (accountEventPublisher== null) {
        accountEventPublisher = (ApplicationEventPublisher) ApplicationContextHolder.getContext().getBean(AccountEventPublisherConfig.EVENT_PUBLISHER_NAME);
      }
      accountEventPublisher.publishEvent(event);
    }
  }
  </code></pre>
  
  <p>The following code is what intercepts the events</p>
  
  <pre><code>@Component
  public class FileUploadTriggerListener implements ApplicationListener&lt;AccountTrigger&gt; {
  
    @Autowired
    private PatchFileService fileService;
  
    @Autowired
    private ApplicationLogService appLogService;
  
    @Autowired
    private ExecutorService executor;
  
    @Override
    public void onApplicationEvent(AccountTrigger trigger) {
      if (trigger.getType() != TriggerType.FILE_UPLOADED) return;
      executor.schedule(new Runnable() {
        @Override
        public void run() {
           System.out.println("Hello World");
        });
      }
    }
  }
  </code></pre>
  
  <p>And Here is the Class that extends <code>ApplicationEvent</code></p>
  
  <pre><code>public class AccountTrigger extends ApplicationEvent {
  
    private static final long serialVersionUID = 2139401946845273241L;
  
    private Integer userId;
  
    private TriggerType type;
  
    private List&lt;Object&gt; resources = new ArrayList&lt;&gt;();
  
    public Integer getUserId() {
      return userId;
    }
  
    public void setUserId(Integer userId) {
      this.userId = userId;
    }
  
    public List&lt;Object&gt; getResources() {
      return resources;
    }
  
    public void setResources(List&lt;Object&gt; resources) {
      this.resources = resources;
    }
  
    public TriggerType getType() {
      return type;
    }
  
    public void setType(TriggerType type) {
      this.type = type;
    }
  }
  </code></pre>
  
  <p>All ApplicationEvents are of type <code>AccountTrigger</code> with an enumeration of trigger types. The only trigger type I use right now is <code>FILE_UPLOAD</code>. </p>
  
  <p>I am not sure why this bean won't stop and what I am doing wrong.</p>