title: Dependency injection in a simple Spring application does not work (injection Service into Controller variable)
body: <p>I have a really simple project.</p>
  
  <p>It has the main class:</p>
  
  <pre><code>package com.example;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  
  @ComponentScan
  @EnableAutoConfiguration
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>A controller:</p>
  
  <pre><code>package com.example;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.util.StringUtils;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  
  @Controller
  public class Controller {
  
      @Autowired
      MyService myService;
  
      @RequestMapping("/application")
      public String getApp(ModelMap model) {
          return "application";
      }
  
      @RequestMapping("/application/home")
      public String do(@RequestParam(value="input", required=false) String input, ModelMap model) {
          if (!StringUtils.isEmpty(input)) {
              model.addAttribute(INPUT_ATT, input);
              model.addAttribute(OUTPUT_ATT, myService.do(input));
          }
          return "home";
      }
  
  }
  </code></pre>
  
  <p>And a service (interface, implementation):</p>
  
  <pre><code>package com.example;
  
  public interface MyService {
  
      String do(String input);
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>package com.example;
  
  import org.springframework.stereotype.Service;
  
  @Service
  public class MyServiceImpl implements MyService {
  
      @Override
      public String do(String input) {
          return "result";
      }
  
  }
  </code></pre>
  
  <p>Unfortunately, an instance of MyServiceImpl does not get injected to myService variable in controller class.</p>
  
  <p>What should I do to solve that problem?</p>
  
  <p>With regards,</p>