title: How to use a spring profile bean in another bean with default profile?
body: <p>I have a bean under the "dev" profile:</p>
  
  <pre><code>@Bean(name="internalDL")
  public Map&lt;Client, List&lt;String&gt;&gt; internalDistributionLists() {
      Map&lt;Client, List&lt;String&gt;&gt; distributionLists = new HashMap&lt;Client, List&lt;String&gt;&gt;();
      distributionLists.put(Client.DL_NAME, Arrays.asList("example@blah.com"));
      return distributionLists;
  }
  </code></pre>
  
  <p>I need to use this bean in another bean:</p>
  
  <pre><code>@Autowired
  @Qualifier("internalDL")
  private Map&lt;String, List&lt;String&gt;&gt; internalMailingList;
  
  @Bean(name="internalMailingDetails")
  public Map&lt;Client, MailingDetails&gt; internalMailingDetails() {
      Map&lt;Client, MailingDetails&gt; internalMailingDetails = new HashMap&lt;Client, MailingDetails&gt;();
  
      MailingDetails details = new MailingDetails();
  
      details.setMailingList(internalMailingList.get(Client.DL_NAME));
      details.setTemplateSubject("someTemplate");
      details.setTemplateBody("someTemplate");
      internalMailingDetails.put(Client.DL_NAME, details);
  
      return internalMailingDetails;
  }
  </code></pre>
  
  <p>Now the mailing template is the same for all environments so i haven't put it in a config that's marked with a particular profile.</p>
  
  <p>I tried initializing the profile both by initializing the <code>ApplicationContextInitializer&lt;ConfigurableApplicationContext&gt;</code> class:</p>
  
  <pre><code>@Override
  public void initialize(ConfigurableApplicationContext applicationContext) {
      applicationContext.getEnvironment().setActiveProfiles("dev");
  }
  </code></pre>
  
  <p>and by putting it as a context parameter:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;spring.profiles.active&lt;/param-name&gt;
      &lt;param-value&gt;dev&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>None of them seem to work though. It keeps throwing a bean not found exception.</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Map com.fmr.bpo.asyncprocessingframework.invocator.wiring.configuration.pojo.common.RootConfig.internalMailingList</p>
  </blockquote>
  
  <p>Thanks for the help.</p>