title: Spring Autowire retrieves the wrong class
body: <p>I have</p>
  
  <pre><code>public abstract class AbstractClass&lt;T&gt; {
    public abstract MyStatus getStatus();
    public void test() {
       System.out.println(getStatus().testField());
    }
  }
  </code></pre>
  
  <p>for Dogs I have </p>
  
  <pre><code>@Component("dogs")
  public class Dogs extends AbstractClass&lt;Dogs&gt;{
     @Autowired
     MyStatus statusField;
  
     @PostConstruct
     private void init() {
        statusField.setTest("dogs");
     }
  
     public getStatus() {
       return statusField;
     }
  }
  </code></pre>
  
  <p>for cats I have</p>
  
  <pre><code>@Component("cats")
  public class Cats extends AbstractClass&lt;Cats&gt;{
     @Autowired
     MyStatus statusField;
  
     @PostConstruct
     private void init() {
        statusField.setTest("cats");
     }
  
     public getStatus() {
       return statusField;
     }
  }
  </code></pre>
  
  <p>and for the StatusContainer I have </p>
  
  <pre><code>@Component
  @Data
  public class MyStatus&lt;T&gt; {
     public String test; // and other options from the application.properties file
  }
  </code></pre>
  
  <p>I would expect that if I <code>@Autowired</code> <code>Dogs</code> I get for the status field <code>dogs</code> and for the <code>Cats</code> I'll get <code>cats</code>. </p>
  
  <pre><code>public class ClassA {
     @Autowired
     @Qualifier("dogs")
     Dogs myDogEntity;
  }
  
  public class ClassB {
     @Autowired
     @Qualifier("cats")
     Cats myCatEntity;
  }
  </code></pre>
  
  <p>Matter of fact is that if I print the information of <code>MyStatus</code> I get everytime <code>cats</code> (or everytime <code>dogs</code>). I would have exptected that the container is initiated differently and injected with the appropriate instance. But thats not true. </p>
  
  <p>Is there a <em>simple</em> way to have separete containers for different objects instead of injecting the same?</p>
  
  <p><strong>UPDATE</strong> Unfortunately I have had some typos in my orginal code. Fixed them - hopefully all.</p>
  
  <p>I finally figured out that the major problem is/was that Spring creates only one instance of a component. In my case <code>MyStatus</code>. Consequently this one instance is injected into the other classes. Any manipulation on this one class will lead to the side effect that it manipulates the other.</p>
  
  <p>My solution: Split the config into two parts - one which is Spring related and one the instance, e.g. <code>Cats</code> or <code>Dogs</code> will handle indiviudally - without Spring (injection)!!!</p>