Я работаю с пружиной 5, я написал класс CacheManger, который я использую для кэширования данных вручную, я автоматически связал конструктор с помощью аннотации. Я вводил этот объект в другие весенние бобы. Проблема в том, что когда я запускаю tomcat, этот конструктор вызывается три раза. Я не знаю почему? Пожалуйста, помогите мне.
Это устаревшая система, встроенная в Struts, необходимо обновить ее, пожалуйста, см. Также web. xml Содержимое, почему создается контекст для ActionServlet
Это мой класс: -
@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<Integer, ArrayList<ALang>>();
}
ArrayList<AValue> list = this.mapOfValueMaps.get(branchId);
if (list == null) {
list = new ArrayList<ALang>(1);
this.mapOfDealerLang.put(branchId, list);
} else
list.clear();
for (Iterator iter = tmpLst.iterator(); iter.hasNext();) {
AValue element = (AValue) iter.next();
list.add(element);
}
}
Это мой слой Дао
@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;
}
}
Это DI для этого: -
@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;
}
}
}
Журнал консоли после запуска tomcat: -
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
Этот веб-сайт. xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>