title: Construtor Autowiring calling three times (Spring 5)
body: <p>I am working with spring 5, I have written a class CacheManger which I use to cache data manually, I have autowired the constructor with help of annotation. I have injected this object in other spring beans. The problem is that when I start the tomcat, this constructor is being called three times. I don't know why? Please help me out.</p>
  
  <p>This is a legacy system built in struts , need to upgrade this, pls see also web.xml contents, why context is being created for ActionServlet</p>
  
  <p>This is my class:-</p>
  
  <pre><code>@Component
  public class CacheManager {
  
      UtilDAO utilDao;
  
      @Autowired
      public CacheManager(UtilDAO utilDAO) {
          System.out.println("Calling the CacheManager Constructor...");
          this.utilDao = utilDAO;
          loadValueMaps();
      }
  
      private HashMap mapOfValueMaps = null;
  
  
      @Transactional(propagation = Propagation.SUPPORTS)
      public void loadValueMaps(int branchId) {
          List tmpLst = this.utilDao.getValueMapsList(branchId);
  
          if (this.mapOfDealerLang == null) {
              this.mapOfDealerLang = new HashMap&lt;Integer, ArrayList&lt;ALang&gt;&gt;();
          }
  
          ArrayList&lt;AValue&gt; list = this.mapOfValueMaps.get(branchId);
          if (list == null) {
              list = new ArrayList&lt;ALang&gt;(1);
              this.mapOfDealerLang.put(branchId, list);
          } else
              list.clear();
  
          for (Iterator iter = tmpLst.iterator(); iter.hasNext();) {
              AValue element = (AValue) iter.next();
              list.add(element);
          }
      }
  </code></pre>
  
  <p>This is my Dao Layer</p>
  
  <pre><code>@Repository
  public class UtilDAOImpl extends DatabaseConnection implements UtilDAO {
  
      @Autowired
      @Qualifier("sessionFactoryBean")
      SessionFactory sessionfactoryBean;
  
      @Autowired
      public void setSessionFactoryBean() {
          setSessionFactory(sessionfactoryBean);
      }
  
      @Override
      @Transactional(propagation = Propagation.SUPPORTS)
      public List getValueMapsList() {
          String query = "from AValue as blk  where blk.blkActive = :blval";
          List reqList = findbyParam(query, "blval", true);
          Set setItems = new LinkedHashSet(reqList);
          reqList.clear();
          reqList.addAll(setItems);
          return reqList;
      }
  }
  </code></pre>
  
  <p>This is DI for this:- </p>
  
  <pre><code>@Component
  public class ListActionManager {
  
  
      @Autowired
      ViewService vwService;
  
      @Autowired
      CacheManager cachMang;
  
  
      public void getList(int pageNo,DisplayListForm form, SessionBean bean) throws Exception{
          try{
              ListView lstVw=null;
              int maxResult=25;
              int totalRecords=0;
  
              lstVw = vwService.getList(bean.getBranch_ind(),ssUsrBn.getBranch_main_ind(),pageNo,maxResult,totalRecords);}
              form.setdata(lstVw);
          }catch(Exception ex){
              throw ex;
          }
      }
  }
  </code></pre>
  
  <p>Console log after starting tomcat:-</p>
  
  <pre><code>Apr 25, 2020 11:55:29 AM org.apache.catalina.startup.TaglibUriRule body
  INFO: TLD skipped. URI: http://struts.apache.org/tags-html is already defined
  Apr 25, 2020 11:55:29 AM org.apache.catalina.startup.TaglibUriRule body
  INFO: TLD skipped. URI: http://struts.apache.org/tags-logic is already defined
  Apr 25, 2020 11:55:29 AM org.apache.catalina.startup.TaglibUriRule body
  INFO: TLD skipped. URI: http://struts.apache.org/tags-nested is already defined
  Apr 25, 2020 11:55:29 AM org.apache.catalina.startup.TldConfig execute
  INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  Apr 25, 2020 11:55:29 AM org.apache.catalina.core.ApplicationContext log
  INFO: No Spring WebApplicationInitializer types detected on classpath
  Apr 25, 2020 11:55:29 AM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing Spring root WebApplicationContext
  log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
  log4j:WARN Please initialize the log4j system properly.
  
  
  **Calling the CacheManager Constructor...**
  
  
  Apr 25, 2020 11:55:35 AM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing Spring DispatcherServlet 'actionbean'
  
  
  **Calling the CacheManager Constructor...**
  
  
  Apr 25, 2020 11:55:37 AM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing WebApplicationContext for Struts ActionServlet 'servlet', module ''
  
  **Calling the CacheManager Constructor...**
  
  
  Apr 25, 2020 11:55:39 AM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["http-bio-8080"]
  Apr 25, 2020 11:55:39 AM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["ajp-bio-8009"]
  Apr 25, 2020 11:55:39 AM org.apache.catalina.startup.Catalina start
  INFO: Server startup in 12491 ms
  </code></pre>
  
  <p>This web.xml</p>
  
  <pre><code>    &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  
  
    &lt;servlet&gt;
          &lt;servlet-name&gt;servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
            &lt;param-name&gt;config&lt;/param-name&gt;
            &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;
          &lt;/init-param&gt;       
          &lt;init-param&gt;
              &lt;param-name&gt;debug&lt;/param-name&gt;
              &lt;param-value&gt;2&lt;/param-value&gt;
          &lt;/init-param&gt;       
          &lt;init-param&gt;
              &lt;param-name&gt;detail&lt;/param-name&gt;
              &lt;param-value&gt;2&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;  
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
  </code></pre>