Q:

Controller class is not reinitialized in Spring MVC

I am using spring Mvc Framework. My controller class looks like this.
public class UpdateStockController extends AbstractWizardFormController {

StockRegisterService stockRegisterService;
DimensionStoneService dimensionStoneService;
MineralService mineralService;
AutoPopulatingList openDimensionStoneBeans=new AutoPopulatingList(DimensionStoneBean.class);
AutoPopulatingList todayDimensionStoneBeans=new AutoPopulatingList(DimensionStoneBean.class);
StockRegister stockRegister;
List<DimensionStone> openDimensionStones=new ArrayList<DimensionStone>();
List<DimensionStone> todayDimensionStones=new ArrayList<DimensionStone>();
float cumulativeStockOrg;
boolean flag1;
boolean flag2;
public StockRegisterService getStockRegisterService() {
    return stockRegisterService;
}
public void setStockRegisterService(StockRegisterService stockRegisterService) {
    this.stockRegisterService = stockRegisterService;
}   
public DimensionStoneService getDimensionStoneService() {
    return dimensionStoneService;
}
public void setDimensionStoneService(DimensionStoneService dimensionStoneService) {
    this.dimensionStoneService = dimensionStoneService;
}   
public MineralService getMineralService() {
    return mineralService;
}
public void setMineralService(MineralService mineralService) {
    this.mineralService = mineralService;
}
public UpdateStockController(){
    setSessionForm(true);
}   
@Override
protected Object formBackingObject(HttpServletRequest request)throws Exception {

    String applicationId=null;
    String serviceId=null;
    try{
        applicationId=(String)request.getParameter("appId").trim();
        serviceId=(String)request.getParameter("serviceId").trim();
    }catch (NullPointerException e) {
        HttpSession session=request.getSession();
        applicationId=(String) session.getAttribute("applicationId");
        serviceId=(String) session.getAttribute("serviceId");
    }
    String mineralId=(String)request.getParameter("mineralIdAndName").trim().split(":")[0];
    String mineralName=(String)request.getParameter("mineralIdAndName").trim().split(":")[1];
    if(mineralId.equals("10")){
        flag2=true;
    }
    System.out.println("..............................flag2 : "+flag2+".......................");
    System.out.println("..............................flag1 : "+flag1+".......................");
    HttpSession session=request.getSession();
    session.setAttribute("applicationId", applicationId);
    session.setAttribute("serviceId",serviceId);
    Date productionDate=new Date(); 
    UpdateStockBean updateStockBean=new UpdateStockBean();
    updateStockBean.setMineralId(mineralId);
    updateStockBean.setMineralName(mineralName);           
    updateStockBean.setAccidentOccured("NO");
    updateStockBean.setCompPaid("NO");
    stockRegister=new StockRegister();
    @SuppressWarnings("rawtypes")
    List ckeckTodayStockRegisterList=stockRegisterService.retrieveDataFromStockRegister(applicationId,productionDate,mineralId);       
    if(ckeckTodayStockRegisterList.isEmpty()){
        System.out.println("..............................If1.......................");
        @SuppressWarnings("rawtypes")
        List openingBalFromPreviousStockRegisterList=stockRegisterService.retrieveOpeningBalance(applicationId,mineralId);  
        flag1=true;
        if (!openingBalFromPreviousStockRegisterList.isEmpty()) {
            System.out.println("..............................If2.......................");
            flag1=false;
            stockRegister=(StockRegister)openingBalFromPreviousStockRegisterList.get(0);
            stockRegister.setStockRegisterId(0);
            if(stockRegister.getBalanceQuantity()!=null){
                updateStockBean.setOpenbalance(stockRegister.getBalanceQuantity());                     
            }   
            cumulativeStockOrg=stockRegister.getCumulativeStock();
            System.out.println(".............................."+cumulativeStockOrg+".......................");
        }              
    }else{
        System.out.println("..............................else.......................");
        stockRegister=(StockRegister) ckeckTodayStockRegisterList.get(0);
        long stockRegId=stockRegister.getStockRegisterId();
        openDimensionStones=dimensionStoneService.getOpenDimensionStones(stockRegId);
        todayDimensionStones=dimensionStoneService.getTodayDimensionStones(stockRegId);
        updateStockBean.setOpenbalance(stockRegister.getOpeningBal());
        updateStockBean.setTodayproduction(stockRegister.getQuantityProduced());
        updateStockBean.setNoOfMale(stockRegister.getNoOfMaleEmp());
        updateStockBean.setNoOfFemale(stockRegister.getNoOfFemaleEmp());
        updateStockBean.setAccidentOccured(stockRegister.getAccidentOccured());
        updateStockBean.setDescriptionAccident(stockRegister.getAccidentDescription());
        updateStockBean.setCompPaid(stockRegister.getCompensationPaid());
        updateStockBean.setCompDetails(stockRegister.getCompensationDet());
        updateStockBean.setCompAmount(stockRegister.getCompensationAmt());
        cumulativeStockOrg=stockRegister.getCumulativeStock()-stockRegister.getQuantityProduced();
        for (Iterator<DimensionStone> iterator = openDimensionStones.iterator(); iterator.hasNext();) {
            System.out.println("..............................Haii77777777777.......................");
            DimensionStone dimensionStone=iterator.next();  
            DimensionStoneBean dimensionStoneBean=new DimensionStoneBean();
            dimensionStoneBean.setStoneNo(Integer.parseInt(dimensionStone.getStoneNo().toString()));
            dimensionStoneBean.setLength(dimensionStone.getLength());
            dimensionStoneBean.setBreadth(dimensionStone.getBreadth());
            dimensionStoneBean.setHeight(dimensionStone.getHeight());
            dimensionStoneBean.setDimension(dimensionStone.getDimension());
            dimensionStoneBean.setIsIssued(dimensionStone.getIsIssued());
            openDimensionStoneBeans.add(dimensionStoneBean);
        }
        updateStockBean.setOpenDimensionStones(openDimensionStoneBeans);
        for (Iterator<DimensionStone> iterator = todayDimensionStones.iterator(); iterator.hasNext();) {
            System.out.println("..............................Haiiii8888888888888.......................");
            DimensionStone dimensionStone=iterator.next();
            DimensionStoneBean dimensionStoneBean=new DimensionStoneBean();
            dimensionStoneBean.setStoneNo(Integer.parseInt(dimensionStone.getStoneNo().toString()));
            dimensionStoneBean.setLength(dimensionStone.getLength());
            dimensionStoneBean.setBreadth(dimensionStone.getBreadth());
            dimensionStoneBean.setHeight(dimensionStone.getHeight());
            dimensionStoneBean.setDimension(dimensionStone.getDimension());
            dimensionStoneBean.setIsIssued(dimensionStone.getIsIssued());
            todayDimensionStoneBeans.add(dimensionStoneBean);
        }
        updateStockBean.setTodayDimensionStones(todayDimensionStoneBeans); 
    } 
    return updateStockBean;
}

@SuppressWarnings("unchecked")
@Override
protected ModelAndView processFinish(HttpServletRequest req,HttpServletResponse res, Object cmd, BindException be)
throws Exception {
    float cumulativeStock;
    float dimensionCumulativeVolume=cumulativeStockOrg;

    UpdateStockBean bean = (UpdateStockBean)cmd;
    Long openingBalance=bean.getOpenbalance();
    Long quantityProduced=(Long)bean.getTodayproduction();
    Long totalQuantity=openingBalance+quantityProduced;
    Long balanceQuantity=totalQuantity;
    System.out.println("..............................flag2 : "+flag2+".......................finish");
    System.out.println("..............................flag1 : "+flag1+".......................finish");
    if(flag1){
        System.out.println("..............................flag true.......................1");
        cumulativeStock=(Float.parseFloat(openingBalance.toString())+Float.parseFloat(quantityProduced.toString()));
    }else{
        System.out.println("..............................flag false.......................1");
        cumulativeStock=cumulativeStockOrg+quantityProduced;
    }
    System.out.println(".............................."+cumulativeStock+".......................1");
    if(stockRegister.getStockRegisterId()==0){
        stockRegister.setStockRegisterId(stockRegisterService.getMaximumValueStockRegisterId()+1);
    }   
    Application application=new Application();
    application.setApplicationId(Long.parseLong(req.getSession().getAttribute("applicationId").toString().trim()));
    stockRegister.setApplication(application);
    stockRegister.setProductionDate(new SimpleDateFormat("dd-MMM-yyyy").parse(bean.getProductiondate()));
    stockRegister.setOpeningBal(openingBalance);
    stockRegister.setMineralId(Long.parseLong(bean.getMineralId()));
    stockRegister.setQuantityProduced(quantityProduced);
    stockRegister.setTotalQuantity(totalQuantity);
    stockRegister.setBalanceQuantity(balanceQuantity);
    stockRegister.setNoOfFemaleEmp((Integer)bean.getNoOfFemale());
    stockRegister.setNoOfMaleEmp(bean.getNoOfMale());
    stockRegister.setAccidentOccured(bean.getAccidentOccured());
    stockRegister.setAccidentDescription(bean.getDescriptionAccident());
    stockRegister.setCompensationPaid(bean.getCompPaid());
    stockRegister.setCompensationAmt(bean.getCompAmount());
    stockRegister.setCompensationDet(bean.getCompDetails());
    stockRegister.setCumulativeStock(cumulativeStock);  
    System.out.println(".............................."+cumulativeStock+".......................2");

    dimensionStoneService.deleteDimensionStonesOnToday(openDimensionStones);
    dimensionStoneService.deleteDimensionStonesOnToday(todayDimensionStones);
    openDimensionStoneBeans=bean.getOpenDimensionStones();  
    if(openDimensionStoneBeans.size()>bean.getOpenbalance()){
        int size=openDimensionStoneBeans.size();
        int j=(int) bean.getOpenbalance();
        for(int i=(int) bean.getOpenbalance();i<size;i++){
            openDimensionStoneBeans.remove(j);
        }
        bean.setOpenDimensionStones(openDimensionStoneBeans);
        cmd=(Object)bean;
    }       
    openDimensionStones=new ArrayList<DimensionStone>();
    for (Iterator<DimensionStoneBean> iterator = openDimensionStoneBeans.iterator(); iterator.hasNext();) {
        System.out.println("..............................Haiiiii11111.......................");
        DimensionStoneBean dimensionStoneBean = iterator.next();
        DimensionStone dimensionStone=new DimensionStone();
        dimensionStone.setStoneNo(Long.parseLong(((Integer)dimensionStoneBean.getStoneNo()).toString()));
        dimensionStone.setLength(dimensionStoneBean.getLength());
        dimensionStone.setBreadth(dimensionStoneBean.getBreadth());
        dimensionStone.setHeight(dimensionStoneBean.getHeight());
        dimensionStone.setDimension(dimensionStoneBean.getDimension());
        dimensionStone.setIsIssued(dimensionStoneBean.getIsIssued());
        dimensionStone.setStockType("opening");
        dimensionStone.setStockRegisterId(stockRegister.getStockRegisterId());
        dimensionCumulativeVolume=dimensionCumulativeVolume+dimensionStoneBean.getDimension();
        openDimensionStones.add(dimensionStone);
    }       
    todayDimensionStoneBeans=bean.getTodayDimensionStones();    
    if(todayDimensionStoneBeans.size()>bean.getTodayproduction()){
        int size=todayDimensionStoneBeans.size();
        int j=(int) bean.getTodayproduction();
        for(int i=(int) bean.getTodayproduction();i<size;i++){
            todayDimensionStoneBeans.remove(j);
        }
        bean.setTodayDimensionStones(todayDimensionStoneBeans);
        cmd=(Object)bean;
    }
    todayDimensionStones=new ArrayList<DimensionStone>();
    for (Iterator<DimensionStoneBean> iterator = todayDimensionStoneBeans.iterator(); iterator.hasNext();) {
        System.out.println("..............................Haiiiii22222.......................");
        DimensionStoneBean dimensionStoneBean = iterator.next();
        DimensionStone dimensionStone=new DimensionStone();
        dimensionStone.setStoneNo(Long.parseLong(((Integer)dimensionStoneBean.getStoneNo()).toString()));
        dimensionStone.setLength(dimensionStoneBean.getLength());
        dimensionStone.setBreadth(dimensionStoneBean.getBreadth());
        dimensionStone.setHeight(dimensionStoneBean.getHeight());
        dimensionStone.setDimension(dimensionStoneBean.getDimension());
        dimensionStone.setIsIssued(dimensionStoneBean.getIsIssued());
        dimensionStone.setStockType("current");
        dimensionStone.setStockRegisterId(stockRegister.getStockRegisterId());
        dimensionCumulativeVolume=dimensionCumulativeVolume+dimensionStoneBean.getDimension();
        todayDimensionStones.add(dimensionStone);
    }   
    if(flag2){
        System.out.println(".............................."+dimensionCumulativeVolume+".......................3");
        stockRegister.setCumulativeStock(dimensionCumulativeVolume);
    }       
    stockRegisterService.saveOrupdateStockRegister(stockRegister);      
    dimensionStoneService.saveOrupdateDimensionStones(openDimensionStones);
    openDimensionStoneBeans.clear();
    dimensionStoneService.saveOrupdateDimensionStones(todayDimensionStones);
    todayDimensionStoneBeans.clear();
    HttpSession session=req.getSession();
    String appId=(String) session.getAttribute("applicationId");
    String serviceId=(String) session.getAttribute("serviceId");
    String mineralIdAndName=bean.getMineralId()+":"+bean.getMineralName();
    return new ModelAndView(new InternalResourceView("updateStock.c?appId="+appId+"&serviceId="+serviceId+"&mineralIdAndName="+mineralIdAndName));
}
@Override
protected ModelAndView processCancel(HttpServletRequest request,HttpServletResponse response, Object command, BindException errors)
throws Exception {

    UpdateStockBean bean=(UpdateStockBean)command;
    String cancelCheck=request.getParameter("cancelCheck");
    HttpSession session=request.getSession();
    String appId=(String) session.getAttribute("applicationId");
    String serviceId=(String) session.getAttribute("serviceId");
    String mineralIdAndName=bean.getMineralId()+":"+bean.getMineralName();
    if(cancelCheck.equals("1")){
        response.sendRedirect("tabs.c?action=home_tab_emp");
        return new ModelAndView(new InternalResourceView("tabs.nic?action=home_tab_emp"));
    }else if(cancelCheck.equals("2")){
        return new ModelAndView(new InternalResourceView("updateStock.c?appId="+appId+"&serviceId="+serviceId+"&mineralIdAndName="+mineralIdAndName));
    }else{
        response.sendRedirect("tabs.nic?action=mineralSelect&appId="+appId+"&serviceId="+serviceId);
        return new ModelAndView(new InternalResourceView("tabs.c?action=mineralSelect&appId="+appId+"&serviceId="+serviceId));
    }         
}
@Override
protected void validatePage(Object command, Errors errors, int page) {
    UpdateStockValidator updateStockValidator=new UpdateStockValidator();          
    switch(page){
    case 0:          
        updateStockValidator.validateFormStart(command, errors);
        break; 
    case 1:
        break;
    case 2:
        updateStockValidator.validateForm2(command, errors);
        break;           
    case 3:
        updateStockValidator.validateForm3(command, errors);
        break;    
    case 4:          
        updateStockValidator.validateFormStart(command, errors);
        break;       
    }
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked"})
protected Map referenceData(HttpServletRequest request, Object command,Errors errors, int page) throws Exception {

    Map map = new HashMap();
    UpdateStockBean bean = (UpdateStockBean)command;
    String applicationId=(String) request.getSession().getAttribute("applicationId");
    String mineralId=bean.getMineralId();
    Date productionDate=new Date();        
    Calendar cal = new GregorianCalendar();
    cal.setTime(productionDate);
    cal.add(Calendar.DAY_OF_MONTH, -30);
    Date today30 = cal.getTime(); 
    map.put("stockRegisters", stockRegisterService.stockRegisterBetweenTwoDaysWithApplicationId(applicationId,mineralId,today30,productionDate));      
    map.put("ckeckOpeningBalance",stockRegisterService.retrieveDataBeforeProductionDate(applicationId,mineralId,productionDate));  
    map.put("ckeckDimensionStone",mineralService.getMineralByApplicationId(applicationId));
    map.put("mineralList",mineralService.getMineralObjectsByApplicationId(applicationId));
    openDimensionStoneBeans=bean.getOpenDimensionStones();
    if(openDimensionStoneBeans.size()>bean.getOpenbalance()){
        int size=openDimensionStoneBeans.size();
        int j=(int) bean.getOpenbalance();
        for(int i=(int) bean.getOpenbalance();i<size;i++){             
            openDimensionStoneBeans.remove(j);
        }      
        bean.setOpenDimensionStones(openDimensionStoneBeans);
        command=(Object)bean;
    }
    todayDimensionStoneBeans=bean.getTodayDimensionStones();  
    if(todayDimensionStoneBeans.size()>bean.getTodayproduction()){
        int size=todayDimensionStoneBeans.size();
        int j=(int) bean.getTodayproduction();
        for(int i=(int) bean.getTodayproduction();i<size;i++){             
            todayDimensionStoneBeans.remove(j);
        }      
        bean.setTodayDimensionStones(todayDimensionStoneBeans);
        command=(Object)bean;
    }
    return map;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected ModelAndView showForm(HttpServletRequest req,HttpServletResponse res, BindException be) throws Exception {
    HttpSession ses = req.getSession();
    Map pageMap = new HashMap();
    pageMap.put("erType", "");
    pageMap.put("pageType", "");
    if(ses.getAttribute("connection") == null){
        pageMap.put("erType", "sessionExpired");
        //pageMap.put("pageType", "inner");
        return new ModelAndView("page1",pageMap);
    }
    try{
        if(ses.getAttribute("loginType").toString().trim().equals("Employee")){
        }else if(ses.getAttribute("loginType").toString().trim().equals("Applicant")){
        }else if(ses.getAttribute("loginType").toString().trim().equals("Agent")){
        }
    }catch (Exception e){e.printStackTrace();return new ModelAndView(new InternalResourceView("login.nic"));}
    return super.showForm(req, res, be);
}

}
here the variables
List<DimensionStone> openDimensionStones=new ArrayList<DimensionStone>();
List<DimensionStone> todayDimensionStones=new ArrayList<DimensionStone>();
float cumulativeStockOrg;
boolean flag1;
boolean flag2;

are initialized ones,they are not cleared after execution.That is the value of the variables exists in another execution also.As a result program logic is not working correctly
configuaration file is
<beans>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
  <prop key="updateStock.c">UpdateStockController</prop>
</props>
</property>
</bean>

    <bean id="UpdateStockController" class="mams.web.UpdateStockController">
<property name="commandName"><value>updateStock</value></property>
<property name="commandClass">
    <value>mams.web.beans.UpdateStockBean</value>
</property>
<property name="stockRegisterService" ref="StockRegisterService"></property>
<property name="dimensionStoneService" ref="DimensionStoneService"></property>
<property name="mineralService" ref="MineralService"></property>
<property name="validator" ref="UpdateStockValidator"></property>
<property name="pages">
<list>
<!--      <value>showMineralsForStock</value>-->
      <value>updateStock</value>
      <value>addOrEditOpenBalane</value>
      <value>addOrEditOpenDimensionStone</value>
      <value>addOrEditTodayDimensionStone</value>
      <value>updateStock</value>     
</list>
</property>
</bean>

A:

Spring controollers are singletons (like servlets). There is only one instance per controller type shared across all users. They must be stateless to be thread safe. 
So just move your class fields into corresponding methods and the problem will go away. 
As mentioned by Bhushan Bhangale, if you want preserve the state of some variable for the same user between HTTP requests then you can store this variable in the HTTP session.

A:

Spring controllers are singletons so if you are relying on global variables in your method execution without threadsafe implemention then you are doing wrong.
You would experience unexpected behavior.
Make those variables local to the method where you need them and you should be fine.

A:

As others have mentioned your controller should be stateless (i.e. not rely on class variables to store state). 
I notice that you use the variables in different methods - if you wish to store state between requests the usual way is to use the session object to store your data.

