title: JSF SessionScoped managed bean - injection of spring bean is null after restarting server
body: <p>In a JSF 2 application, which is developed on tomcat, I have the following SessionScoped managed bean:</p>
  
  <pre><code>@ManagedBean(name = "loginBean")
  @SessionScoped
  public class LoginBean implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      private String login;
      private String password;
  
      @ManagedProperty(value = "#{authenticationService}")
      transient private AuthenticationService authenticationService;
  
      public String login() {
  
          boolean success = authenticationService.login(login, password); // after restarting tomcat, authenticationService is null here!
  
          //........
      }
  }
  </code></pre>
  
  <p><code>authenticationService</code> is a spring's @Service:</p>
  
  <pre><code>@Service("authenticationService")
  public class AuthenticationServiceImpl implements AuthenticationService, Serializable {
  
      private static final long serialVersionUID = 1L;
  
      //....
  }
  </code></pre>
  
  <p>Also, I've defined the session to be saved on the client side:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;client&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p><strong>THE PROBLEM:</strong></p>
  
  <p>the <code>LoginBean</code> works fine when I start tomcat first time in the morning. But if I then restart tomcat and immediately try to access <code>LoginBean.login()</code>, I am getting a NullPointerException on <code>authenticationService</code>.</p>
  
  <p>I have defined <code>authenticationService</code> to be transient so that it won't be saved to the session. But when restarting tomcat, it is not injected again with the refrence to the spring bean <code>authenticationService</code>.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Why is it not re-injected during start up?</li>
  <li>Why did defining <code>authenticationService</code> as transient not signal JSF to re-inject <code>authenticationService</code>?</li>
  <li>Is the problem affected by setting <code>javax.faces.STATE_SAVING_METHOD</code> as <code>client</code>?</li>
  <li>How can I solve this problem? If your solution is affected by the value of <code>javax.faces.STATE_SAVING_METHOD</code>, please explain how.</li>
  </ol>