title: How to access shared bean instance across different classes that returns an integer
body: <p>I have a config class where I have configured a Bean method that returns an integer and I am passing this bean instance in the constructor of two more classes. In first class I am incrementing this bean method, wanted to access incremented count in second class. In first class bean instance(Integer) is incrementing, but not persisting that value to second class where still I get '0' for this bean instance. How I can persist the same value to second class ? Default bean scope is singleton, so that is taken care. Anything am I doing wrong?</p>
  
  <pre><code>@Configuration
  public class LineConfig {
  
   @Bean(name = "getCount")
     public Integer getCount()
      {
          return new Integer(0);
      }
  
  //pls ingnore other logic/syntax as I am focussing only on bean method
   public Step processinvoicejobStep(String fileName,int chunkSize,String jobString) {
             mongoFailedRecordList=new ArrayList&lt;&gt;();
                 Step step;       
                    step =  stepBuilderFactory
                          .get("processinvoiceErrjob"+"-"+fileName)
                          .&lt;invoiceWrapper,invoiceWrapper&gt; chunk(chunkSize)
                          .reader(new invoiceReader(container, azureBlobinvoiceErr,azureBlobinvoiceParsingErr))
           **class 1 &lt;----**.writer(new invoiceWriter(mongoConfig.mongoDB().getCollection(collectionName),mongoConfig.mongoDB(),mongoFailedRecordList,fileName,azureBlobinvoiceErr,azureBlobinvoiceErr,objectMapper,enableStats,threadPool,env,container,writeList,**getInsertCount()**))
          **class 2 &lt;----** .listener(new WriterListener(mongoFailedRecordList,env,container,fileName,azureBlobinvoiceErr,errorData(),writeList,**getCount()**)).build();
  
                  return step;
          }
          return null;
      }
  </code></pre>