title: How can I have a global variable in Spring per request?
body: <p>I'm translating an application based on REST using Spring Framework. Now I need to translate some responses based on the language of the request. For example:</p>
  
  <pre><code>/get-me-an-answer/?lang=es Spanish
  /get-me-an-answer/?lang=en English
  /get-me-an-answer/?lang=fr French
  </code></pre>
  
  <p>I have the variable <code>language_code</code> as a static variable in a class named <code>Translang</code></p>
  
  <pre><code>    class Translang {
  ...
          public static String language_code = null;
  ...
      }
  </code></pre>
  
  <p>The problem is with multithreading, when a new request come will change the language and if another previous request is executing can probably answer in the language modified and not in the original language it requested.</p>
  
  <p>That's the reason of my question: How can I have a global variable in Spring per request to avoid this problem?</p>