title: Why do I need to use spring annotation in my controller?
body: <p>I'm new to play and also to spring. Started to work in a project and if I just create my controller class like this:</p>
  
  <pre><code>package controllers;
  
  import play.mvc.Controller;
  import play.mvc.Result;
  
  public class Users extends Controller {
  
      public Result login(){
          return ok(views.html.login.render());
      }
  
  }
  </code></pre>
  
  <p>I got this exception:</p>
  
  <pre><code>[NoSuchBeanDefinitionException: No qualifying bean of type [controllers.Users] is defined]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uULDx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uULDx.png" alt="enter image description here"></a></p>
  
  <p>But, if I insert this annoation from spring on the top level: </p>
  
  <pre><code>package controllers;
  
  import play.mvc.Controller;
  import play.mvc.Result;
  
  @org.springframework.stereotype.Controller
  public class Users extends Controller {
  
      public Result login(){
          return ok(views.html.login.render());
      }
  
  }
  </code></pre>
  
  <p>The page is rendered. But I don't know why this is happening. I would like to use spring only when is necessary, work with play on its full capacity. So I wonder if I'm doing right using this annotation on my controller.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>import configuration.WebAppConfig;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Import;
  import play.Application;
  import play.GlobalSettings;
  
  /**
   * Application wide behaviour. We establish a Spring application context for the dependency injection system and
   * configure Spring Data.
   */
  public class Global extends GlobalSettings {
  
      /**
       * The name of the persistence unit we will be using.
       */
      static final String DEFAULT_PERSISTENCE_UNIT = "default";
  
      /**
       * Declare the application context to be used - a Java annotation based application context requiring no XML.
       */
      final private AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  
      /**
       * Sync the context lifecycle with Play's.
       */
      @Override
      public void onStart(final Application app) {
          super.onStart(app);
  
          // AnnotationConfigApplicationContext can only be refreshed once, but we do it here even though this method
          // can be called multiple times. The reason for doing during startup is so that the Play configuration is
          // entirely available to this application context.
          ctx.register(SpringDataJpaConfiguration.class);
          ctx.scan("controllers", "models");
          ctx.refresh();
  
          // This will construct the beans and call any construction lifecycle methods e.g. @PostConstruct
          ctx.start();
  
      }
  
      /**
       * Sync the context lifecycle with Play's.
       */
      @Override
      public void onStop(final Application app) {
          // This will call any destruction lifecycle methods and then release the beans e.g. @PreDestroy
          ctx.close();
  
          super.onStop(app);
      }
  
      /**
       * Controllers must be resolved through the application context. There is a special method of GlobalSettings that we
       * can override to resolve a given controller. This resolution is required by the Play router.
       */
      @Override
      public &lt;A&gt; A getControllerInstance(Class&lt;A&gt; aClass) {
          return ctx.getBean(aClass);
      }
  
      /**
       * This configuration establishes the Spring context which in our case is defined in the "other" project.
       */
      @Configuration
      @Import(WebAppConfig.class)
      public static class SpringDataJpaConfiguration {
          // At the moment this class is just a entry point for the "other project" Spring context config, AppContext
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong>
  Guys, now I remember something in this project, we have 2 projects, one developed entirely on <code>java</code> and <code>spring</code> and this one, the webapp. We are importing the <code>.jar</code> built from the first project on this project with play. We are doing like these so we don't have to maintain two different models.</p>