title: SpringBoot error : No bean named 'myController' available
body: <p>I am building a basic program of "hello world" in SpringBoot </p>
  
  <p><strong>Code</strong></p>
  
  <p>MyController.java</p>
  
  <pre><code>package controllers;
  import org.springframework.stereotype.Controller;
  
  @Controller
  public class MyController {
      public String hello() {
          System.out.println("Hello World");
          return "foo";
      }
  }
  </code></pre>
  
  <p>DemoApplication.java</p>
  
  <pre><code>package di.prac;
  
  import java.util.Arrays;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.ApplicationContext;
  
  import controllers.MyController;
  
  @SpringBootApplication
  public class DemoApplication {
  
      public static void main(String[] args) {
          ApplicationContext ctx=SpringApplication.run(DemoApplication.class, args);
          MyController m = (MyController)ctx.getBean("myController");
          m.hello();
          System.out.println("*******"+Arrays.asList(ctx.getBeanDefinitionNames()));
  
      }
  }
  </code></pre>
  
  <p>I am using <strong>eclipse</strong> and created this project from <a href="http://start.spring.io/" rel="noreferrer">http://start.spring.io/</a> without any dependencies.</p>
  
  <p>I learned that Spring create the bean of <em>MyController</em> class with name <em>myController</em> ,but Spring is not able to find <em>myController</em> bean </p>
  
  <p><strong>ERROR</strong></p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    bean named 'myController' available   at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
      at
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)
      at di.prac.DemoApplication.main(DemoApplication.java:16)</p>
  </blockquote>
  
  <p>Please find and explain the error in the Project </p>