title: Spring cannot initialize bean in profile "dev"
body: <p>My code throws this exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Unknown' available
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)
      at core.Main.main(Main.java:38)
  </code></pre>
  
  <p>I am using mixed configuration - XML and Annotation based:</p>
  
  <p><strong>Dev context:</strong></p>
  
  <pre><code>&lt;beans profile="dev"&gt;
  
      &lt;context:component-scan base-package="core"/&gt;
      &lt;context:annotation-config/&gt;
  
      &lt;import resource="classpath:beans/beans.xml"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Beans.xml context:</strong> contains other beans which are initialized in XML - no annotations used there.</p>
  
  <pre><code>&lt;beans profile="dev,default"&gt;
     &lt;bean ...
     &lt;bean ...
  &lt;/beans&gt;
  </code></pre>
  
  <p>And here is problematic <strong>Configuration</strong> (please note the comment below):</p>
  
  <pre><code>@Configuration
  @Profile({"dev"})
  public class MyConfig {
  
      @Bean(value="Unknown")
      @Description("Bean for unknown user")
      public User getUnknownUser() {
          User user = new User(-1);
          user.setUsername("Unknown");
          return user;
      }
  }
  </code></pre>
  
  <p>Spring correctly initializes beans defined in XML - these beans is in <code>default</code> profile. Only the unknown user is in <code>dev</code> profile.</p>
  
  <p><strong>Main class:</strong></p>
  
  <pre><code>ApplicationContext applicationContext = new ClassPathXmlApplicationContext("dev.xml");
  applicationContext.getEnvironment().acceptsProfiles("dev");
  User unknown = (User)applicationContext.getBean("Unknown");
  LOGGER.info(unknown.toString());
  </code></pre>
  
  <p>Thanks for your help</p>