title: Autowire Map with custom class and use aliases to get the correct object reference
body: <p>I have the following code:</p>
  <pre><code>public interface PolicyDetailsService {
      public void display();
  }
  </code></pre>
  <p>Following are the implementations</p>
  <pre><code>@Service(&quot;PolicyDetailsServiceImpl&quot;)
  public class PolicyDetailsServiceImpl implements PolicyDetailsService {
  
      @Override
      public void display() {
          System.out.println(&quot;PolicyDetailsServiceImpl displayed&quot;);
      }
  
  }
  
  public class PreneedPolicyDetailsServiceImpl implements PolicyDetailsService {
  
      @Override
      public void display() {
          System.out.println(&quot;PreneedPolicyDetailsServiceImpl displayed&quot;);
          
      }
  
  }
  
  public class PreneedTrustPolicyDetailsServiceImpl implements PolicyDetailsService {
  
      @Override
      public void display() {
          System.out.println(&quot;PreneedTrustPolicyDetailsServiceImpl displayed&quot;);
          
      }
  
  }
  </code></pre>
  <p>I am creating the objects by creating beans like the following,</p>
  <pre><code>@Bean(name = { &quot;AGENCY-PLI&quot;, &quot;AGENCY-PMM&quot; })
  public PolicyDetailsServiceImpl getPolicyDetailsServiceImpl(
          @Autowired PolicyDetailsServiceImpl policyDetailsServiceImpl) {
  
      return policyDetailsServiceImpl;
  }
  
  @Bean(name = { &quot;AFS-AFS&quot;, &quot;AFS-PMM&quot; })
  public PreneedPolicyDetailsServiceImpl getPreneedPolicyDetailsServiceImpl() {
      return new PreneedPolicyDetailsServiceImpl();
  }
  
  @Bean({ &quot;AFS-PMT&quot; })
  public PreneedTrustPolicyDetailsServiceImpl getPreneedTrustPolicyDetailsServiceImpl() {
      return new PreneedTrustPolicyDetailsServiceImpl();
  }
  </code></pre>
  <p>The controller where i am using the services,</p>
  <pre><code>@Autowired
  Map&lt;String, PolicyDetailsService&gt; policyDetails;
  
  @GetMapping(&quot;/display/{displayName}&quot;)
  public String display(@PathVariable String displayName) {
      
      try {
          policyDetails.get(displayName).display();
      }catch(Exception e) {
          e.printStackTrace();
      }
      
      return &quot;Display Succesfull&quot;;
  }
  </code></pre>
  <p>What i want to acheive:
  If I pass either &quot;AGENCY-PLI&quot; or &quot;AGENCY-PMM&quot; in the REST service call, the map should return PolicyDetailsServiceImpl object.
  It is currently working for &quot;AGENCY-PLI&quot;. On passing &quot;AGENCY-PMM&quot; i am getting NullPointerException as the map is not returing any object.
  My understanding is, the &quot;AGENCY-PLI&quot; is acting as a primary name and the other names are aliases. So if i used it like the following,</p>
  <pre><code>@Autowired
  @Qualifier(&quot;AGENCY-PMM&quot;)
  private PolicyDetailsService policyDetailsService;
  </code></pre>
  <p>I would get the correct object reference.
  So, my question: Is there a way i can get the object from the map on passing aliases.</p>