title: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'eventpublisher' available
body: <p>I have a Spring Boot application. I annotated a class of the project with @Component annotation. Now in my main class, when I am trying to get a bean of the class, I get an exception that it was not able to find the bean. </p>
  
  <pre><code>Exception in thread "main" [2m2017-05-08 09:53:55.303[0;39m [32m INFO[0;39m [35m9112[0;39m [2m---[0;39m [2m[       Thread-2][0;39m [36ms.c.a.AnnotationConfigApplicationContext[0;39m [2m:[0;39m Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4df828d7: startup date [Mon May 08 09:53:54 EDT 2017]; root of context hierarchy
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'eventpublisher' available
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
      at com.fannie.SpringEventGenerationJBsApplication.main(SpringEventGenerationJBsApplication.java:17)
  </code></pre>
  
  <p>My class that is annotated as component is following </p>
  
  <pre><code>@Component
  public class EventPublisher implements ApplicationEventPublisherAware {
      @Autowired
      private ApplicationEventPublisher publisher;
  
      public void eventpublishers() {
          ActualEvent actualEvent = new ActualEvent(this);
          System.out.println(actualEvent);
          publisher.publishEvent(actualEvent);
      }
  
      @Override
      public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
          this.publisher = publisher;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@SpringBootApplication
  @ComponentScan(basePackages = {"com.fannie"})
  public class SpringEventGenerationJBsApplication {
  
      public static void main(String[] args) {
          ApplicationContext context = SpringApplication.run(SpringEventGenerationJBsApplication.class, args);
  
          EventPublisher ep = (EventPublisher) context.getBean("eventpublisher");
  
          ep.eventpublishers();
      }
  </code></pre>