title: Spring injecting a static (global) singleton
body: <p>I have a class that looks like so:</p>
  
  <pre><code>public class Configurator {
      private static Configurator INSTANCE = null;
  
      private int maxRange = 1;
  
      // many other properties; each property has a default value
  
      private static synchronized Configurator getInstance() {
          if(INSTANCE == null)
              return new Configurator();
  
          return INSTANCE;
      }
  
      public static int getMaxRange() {
          getInstance().maxRange;
      }
  
      public static void setMaxRange(int range) {
          getInstance().maxRange = range;
      }
  
      // Getters and setters for all properties follow this pattern
  }
  </code></pre>
  
  <p>It serves as a global configuration object that can be set on app startup, and then is used by dozens of classes throughout the project:</p>
  
  <pre><code>// Called at app startup to configure everything
  public class AppRunner {
      Configurator.setMaxRange(30);
  }
  
  // Example of Configurator being used by another class
  public class WidgetFactory {
      public void doSomething() {
          if(Configurator.getMaxRange() &lt; 50)
              // do A
          else
              // do B
      }
  }
  </code></pre>
  
  <p>I'm now importing this code into a Spring project, and am trying to configure my Sprinig XML (beans). My guess is that I could define a lone <code>Configurator</code> bean like so (or something similar):</p>
  
  <pre><code>&lt;bean id="configurator" class="com.me.myapp.Configurator" scope="singleton"&gt;
      &lt;property name="maxRange" value="30"/&gt;
      &lt;!-- etc., for all properties --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>That way, when <code>WidgetFactory#doSomething</code> executes, Spring will have already loaded the <code>Configurator</code> class and configured it ahead of time.</p>
  
  <p>Is it correct for me to set the <code>scope="singleton"</code>, or does this not matter? Am I setting the static properties correctly? Is there anything else I need to do or consider here? Thanks in advance.</p>