title: Spring 3.1 bean visibility using bean definition profiles
body: <p>I have been experimenting with using <a href="http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/#Enter%20bean%20definition%20profiles">Spring 3.1's bean definition profiles</a> and nested beans.  I had hoped that I could define different beans depending on the active profile.  Consider the following heavily over simplified example such that my Spring context contains something like</p>
  
  <pre><code>&lt;bean id="say" class="test.Say" p:hello-ref="hello"/&gt;
  
  &lt;beans profile="prod"&gt;
      &lt;bean id="hello" class="test.Hello" p:subject="Production!"/&gt;
  &lt;/beans&gt;
  
  &lt;beans profile="dev"&gt;
      &lt;bean id="hello" class="test.Hello" p:subject="Development!"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'say' defined in class path resource
    [applicationContext.xml]: Cannot resolve reference to bean 'hello'
    while setting bean property 'hello'; nested exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    bean named 'hello' is defined     at
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
      at
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
      aJava Result: 1</p>
  </blockquote>
  
  <p>I was expecting that the <strong>hello</strong> bean would be defined according to the active Maven profile (in my case <em>prod</em> or <em>dev</em>).  I'm starting to think that the Spring active profiles (<em>spring.profiles.active</em>) may be completely unrelated to Maven profiles.  </p>
  
  <p>Could somebody please explain where I am going wrong?  (Is this even possible using profiles?).</p>