title: How to create an instance of the class containing main method in a Spring project
body: <p>I'm developing a console application with spring framework and I have a method in the Main class and I need to access that method by creating an instance but when I try to do so an error regarding bean is shown. 
  So how to create an instance of that class correctly.</p>
  
  <p>Application.java</p>
  
  <pre><code>@SpringBootApplication
  public class Application implements CommandLineRunner {
  
  
  @Autowired
  private Repository repository;
  
  
  public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
  }
  
  @Override
  public void run(String... args) throws Exception {
  
      welcome();
  }
  
  public void welcome(){
      -----------------------------
      -----------------------------
      -----------------------------
  }
  }
  </code></pre>
  
  <p>Example.java</p>
  
  <pre><code>public class Example {
  
  Application obj = new Application();
  
  public void check(){
      obj.welcome();
  }
  }
  </code></pre>
  
  <p>As the above code shows I created the instance of the Application class in the traditional way but it won't work. It says  </p>
  
  <blockquote>
    <p>Caused by: org.springframework.beans.BeanInstantiationException:</p>
  </blockquote>
  
  <p>This is my first experience with Spring so please help me. Thanks in advance.</p>