title: Injecting dependencies using @Autowired into objects created with "new ..."
body: <p>I have a problem with injecting a bean into a helper class. It works basically like this: I create an object in the page constructor that does some work, returns some data and I show these on the page. In this helper object, a service should be injected via <code>@Autowired</code> annotation. However, I always get a null pointer exception when I use it. I also tried <code>@SpringBean</code> but it didn't help. On the other hand, when I inject this service directly into the page with <code>@SpringBean</code>, it's accessible and works fine. Do you know where the problem is?</p>
  
  <p>This is the page:</p>
  
  <pre><code>public class Page extends BasePage {
      public Page() {
          HelperObject object = new HelperObject(new Application("APP_NAME"));
          String result = object.getData();
  
          add(new Label("label", result));
      }
  }
  </code></pre>
  
  <p>Helper object:</p>
  
  <pre><code>public class HelperObject {
      private Application app;
  
      @Autowired
      private Service service;
  
      public HelperObject(Application app) {
          this.app = app;
      }
  
      public String getData() {
          // use service, manipulate data, return a string
      }
  }
  </code></pre>