title: Spring Boot @Autowired creating instances on a runtime
body: <p>As most of Spring Boot new users I have a problem with @Autowired :D</p>
  
  <p>I've readed a big amount of topics about this annotation here But still can't find proper solution for my problem.</p>
  
  <p>Let's suppose that we have this Spring Boot hierarchy:</p>
  
  <pre><code>@SpringBootApplication
  public class DemoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  }
  </code></pre>
  
  <p>Class, that we wanna instantiate every time it's called:</p>
  
  <pre><code>@Service
  public class TestWire {
      public TestWire() {
          System.out.println("INSTANCE CREATED: " + this);
      }
  }
  </code></pre>
  
  <p>Out get controller, that creates new SomeRepo object every request:</p>
  
  <pre><code>@RestController
  public class CreatingRepo {
      @RequestMapping("/")
      public void postMessage() {
          SomeRepo repo = new SomeRepo();
      }
  }
  </code></pre>
  
  <p>Finally, class, that uses @Autowired to create  TestWire instances:</p>
  
  <pre><code>public class SomeRepo {
      @Autowired
      private TestWire testWire;
  
      public SomeRepo() {
          System.out.println(testWire.toString());
      }
  }
  </code></pre>
  
  <p>Let's assume, that we make GET request to "/" several times.</p>
  
  <p>So, as a result, TestWire class will isntantiate only when project builds and neither <strong>@Scope(value = "prototype")</strong>, nor <strong>proxyMode = ScopedProxyMode.TARGET_CLASS</strong> wont help.</p>
  
  <p>Any ideas how to create new instances at runtime? I mean, how can we do it in "Spring way"? Without factories and other things, only Spring DI through annotation and configuration.</p>
  
  <p>Upd. A piece of stack trace, where instance created:</p>
  
  <pre><code>2015-11-16 20:30:41.032  INFO 17696 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  INSTANCE CREATED: com.example.TestWire@56c698e3
  2015-11-16 20:30:41.491  INFO 17696 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12f41634: startup date [Mon Nov 16 20:30:37 MSK 2015]; root of context hierarchy
  2015-11-16 20:30:41.566  INFO 17696 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public void com.example.CreatingRepo.postMessage()
  </code></pre>