title: Creating a base controller with autowired-functionality in spring mvc
body: <p>I'm really new to spring but it's okay. I have to set up a spring mvc rest app, that gets some data from a javafx application via <code>SpringApplicationBuilder.properties()</code>. (This is because I have to implement some libs of the gov that are really a pita...). </p>
  
  <p>So I want all rest mvc controllers to extend an Base- or AppController. In this controller (within its constructor), I would like to access the SourceProperties via </p>
  
  <p><code>@Autowired 
  Environment env</code></p>
  
  <p>But it's just null, when my AppController is static. When it's public, spring throws a BeanCreationException (Error creating bean with name 'appController' -> but I don't know how to handle this). </p>
  
  <p>I hope, you can help me. Here is my last approach...</p>
  
  <p><strong>Application.java</strong></p>
  
  <pre><code>public static void main(String[] args) {
     Login = doLogin();
     Map&lt;String, Object&gt; p = new HashMap&lt;String, Object&gt;();
     p.put("Server", Server);
     p.put("Login", Login)";
  }
  </code></pre>
  
  <p><strong>AppController.java</strong></p>
  
  <pre><code>@Controller
  abstract class AppController {
  
      @Autowired
      Environment env
  
      public Login Login;
  
      public AppContoller() {
          //Access env and read Properties-Map and "Login"
          this.Login = .....;
      }
  }
  </code></pre>
  
  <p><strong>DummyController.java</strong></p>
  
  <pre><code>@RestController
  public class dummyController extends AppController {
      @RequestMapping("/greeting")
      public dummy greeting(@RequestParam(value="name", defaultValue="World") String name) {
          return this.Login.SessionKey;
      }
  }
  </code></pre>
  
  <p>Any help is appreciated, many thanks in advance. I hope, my idea is clear.</p>