title: ApplicationEventPublisher is not being autowired into Component
body: <p>I have a Spring Boot app and <code>@Component</code> class which looks like:</p>
  
  <pre><code>@Component
  public class CustomEvent {
  
      @Autowired
      ApplicationEventPublisher publisher;
  
      @PreRemove
      public void onItemDelete(Object entity) {
          System.out.println(" =======PUBLISH====== " + entity);
          publisher.publishEvent(new EntityDeleteEvent&lt;&gt;(entity));
      }
  }
  </code></pre>
  
  <p>When it goes to run above method the first line is printed with proper entity but the <code>publisher.publishEvent</code> line throws a <code>NullPointerException</code>. I suppose it that the <code>ApplicationEventPublisher</code> is not being <code>@Autowired</code> but couldn't find why. Other <code>@Components</code> which are in the app are found by <code>@ComponentScanner</code>.</p>
  
  <p>Of course in my entity this <code>CustomEvent</code> is registered:</p>
  
  <pre><code>@Entity
  @EntityListeners(
          CustomEvent.class
  )
  @Data
  @AllArgsConstructor
  public class Item 
  </code></pre>
  
  <p>The exact error which is thrown looks like:</p>
  
  <pre><code>2017-10-26 16:46:06.190 ERROR 10176 --- [io-8091-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  java.lang.NullPointerException: null
      at com.inventory.events.CustomEvent.onItemDelete(CustomEvent.java:19)
  </code></pre>
  
  <p>Do you have any suggestion why <code>publisher</code> is <code>null</code>?</p>