title: Bean singleton, session creation and initialization
body: <p>I don't know if it is the better way to implement my solution:</p>
  
  <pre><code>@Component
  @Scope("singleton")
  public class GetFromJson implements Serializable{
      /**
       * 
       */
      private static final long serialVersionUID = -8203722696439228358L;
      Map&lt;String, Map&lt;String, ArrayList&lt;String&gt;&gt;&gt; jsonMap;
  
      public Map&lt;String, Map&lt;String, ArrayList&lt;String&gt;&gt;&gt; getJsonMap() { 
          return jsonMap;
      }
  
      public void setJsonMap(Map&lt;String, Map&lt;String, ArrayList&lt;String&gt;&gt;&gt; jsonMap) {
         this.jsonMap= jsonMap;
      }    
  }
  </code></pre>
  
  <p>The class is Serializable because I get the content from a Json from a database and I map the content in an Object GetFromJson (I need do the query in database only one time). For this reason I need use the Object in all my APp, for this reason I think that I need use a Singleton</p>
  
  <p>Somebody publish to me a library to get the JSON from database. the JSON object parse to  <code>Map&lt;String, Map&lt;String, ArrayList&lt;String&gt;&gt;&gt;</code> for this reason I create my <code>GetFromJson</code> class.</p>
  
  <p>Now I have many rest Service, in my rest services I need use my object: GetFromJson to get the content of jsonMap.</p>
  
  <p>I have many questions.</p>
  
  <p>With the annotation <code>@Scope("singleton")</code> I guarantee have the <code>GetFromJson</code> only one instance available in all my app? </p>
  
  <p>Or what is the better way to have in Spring a singleton and session object available in my app?</p>
  
  <p>To access to get the content of jsonMap of GetFromJson  is enough use </p>
  
  <pre><code>@Autowired
  private GetFromJson jsonObject;
  </code></pre>
  
  <p>Or how can I get my singleton class?</p>
  
  <p>and in my rest method service use:</p>
  
  <pre><code> jsonObject.getJsonMap();
  </code></pre>
  
  <p>How can Initialize my singleton, because i am trying initialize my object with:</p>
  
  <pre><code>@Autowired
  private GetFromJson jsonObject;
  
  
  public methodToInitialize(){
      jsonObject = methodLibraryFromDatabase(GetFromJson.class);
  }
  </code></pre>
  
  <p>ANd the IDE tell to me that the field initialization is not used</p>
  
  <p>I need the same logic, but with session Object, I think that if I understand the singleton implementation with my session object will be the same but only changing the anotation to: <code>@Scope("session")</code></p>