title: No bean named but bean is defined
body: <p>I'm working on an update version of grail-oauth-plugin that support last spring-oauth</p>
  
  <p>My plugin version works good and I have implemented a workin oauth2 server.</p>
  
  <p>But now I want to add a custom-grant defined like this</p>
  
  <pre><code>def doWithSpring = {
  
      myTokenGranter(MyTokenGranter)
  
      xmlns oauth:"http://www.springframework.org/schema/security/oauth2"
  
      oauth.'authorization-server'( /* ... many definitions here ... */){
          /* ... many definitions here ... */
          oauth.'custom-grant'('token-granter-ref': "myTokenGranter")
      }
  }
  </code></pre>
  
  <p>But I get an exception telling me:</p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myTokenGranter'
  </code></pre>
  
  <p>But the bean myTokenGranter is defined as you can see. And If I remove the custom-grant definition the project starts and I can access the myTokenGranter bean.</p>
  
  <p>Looking to a fullstack trace I see that the exception occur in the <a href="https://github.com/SpringSource/spring-security-oauth/blob/master/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/config/AuthorizationServerBeanDefinitionParser.java" rel="nofollow">spring oatuh2 server bean definition parse  AuthorizationServerBeanDefinitionParser.java</a> in the line where it try to find my bean</p>
  
  <pre><code>parserContext.getRegistry().getBeanDefinition(customGranterRef);
  </code></pre>
  
  <p>where customGranterRef = "myTokenGranter"</p>
  
  <p>so I suspect there is a bug in Spring Ouath or in Grails BeanBuilder that does not let my "myTokenGranter" to be visible in the server parser. Or making some error in grails bean definition DSL. </p>
  
  <hr>
  
  <p>Thank you for your interest.</p>
  
  <p>Debugging the app more deeply I have found that the problem probably is in how grails BeanBuilder work in translating namespaced spring DSL.</p>
  
  <p>If I debug the point where my bean is checked (in <a href="https://github.com/SpringSource/spring-security-oauth/blob/master/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/config/AuthorizationServerBeanDefinitionParser.java" rel="nofollow">AuthorizationServerBeanDefinitionParser.java</a>)</p>
  
  <p>at row</p>
  
  <pre><code>parserContext.getRegistry().getBeanDefinition(customGranterRef);
  </code></pre>
  
  <p>if I check che result of </p>
  
  <pre><code> parserContext.getRegistry().getBeanDefinitionNames()
  </code></pre>
  
  <p>it show me only this beans</p>
  
  <pre><code>[org.springframework.context.annotation.internalConfigurationAnnotationProcessor
   org.springframework.context.annotation.internalAutowiredAnnotationProcessor
   org.springframework.context.annotation.internalRequiredAnnotationProcessor
   org.springframework.context.annotation.internalCommonAnnotationProcessor
   org.springframework.context.annotation.internalPersistenceAnnotationProcessor
   org.springframework.aop.config.internalAutoProxyCreator
   org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0
   org.springframework.transaction.interceptor.TransactionInterceptor#0
   org.springframework.transaction.config.internalTransactionAdvisor
   oauth2TokenGranter
   oauth2AuthorizationCodeServices
   oauth2AuthorizationRequestManager]
  </code></pre>
  
  <p>And not all other decleared beans...</p>
  
  <hr>
  
  <p>The problem exist even if I move the ouath server declaration inside resources.xml, keeping my custom token granter bean declaration inside resources.groovy. </p>
  
  <p>But the problem solves if I move the custom token bean declaration inside resources.xml.</p>