CacheableApplicationContextResolverImpl extends ApplicationContextResolverImpl implements InitializingBean, DisposableBean { @Override public ApplicationContext resolveApplicationContext( BatchJobData batchJobData) { Cache cache = this.cacheManager.getCache(BLOGIC_CONTEXT_CACHE_KEY); String jobAppCd = batchJobData.getJobAppCd(); ApplicationContext jobAppCtx = cache.get(jobAppCd, ApplicationContext.class); if (jobAppCtx != null) { return jobAppCtx; } Object lockMonitor = getLockMonitor(jobAppCd); synchronized (lockMonitor) { jobAppCtx = cache.get(jobAppCd, ApplicationContext.class); if (jobAppCtx == null) { LOGGER.info(LogId.IAL025019, batchJobData.getJobAppCd()); jobAppCtx = super.resolveApplicationContext(batchJobData); cache.put(jobAppCd, jobAppCtx); } } return jobAppCtx; }  void setCacheManager(CacheManager cacheManager); @Override ApplicationContext resolveApplicationContext(
            BatchJobData batchJobData); @Override void closeApplicationContext(ApplicationContext applicationContext); @Override void afterPropertiesSet(); @Override void destroy(); static final String BLOGIC_CONTEXT_CACHE_KEY; }
@Test public void testResolveApplicationContext01() throws Exception { BatchJobData batchJobData = new BatchJobData(); batchJobData.setJobAppCd("B000001"); ApplicationContext blogicContextFirst = applicationContextResolver .resolveApplicationContext(batchJobData); assertThat(logger.getLoggingEvents(), is(asList(info( "[IAL025019] BLogic context will be cached. jobAppCd:B000001")))); logger.clear(); ApplicationContext blogicContextSecond = applicationContextResolver .resolveApplicationContext(batchJobData); assertFalse(logger.getLoggingEvents().contains(info( "[IAL025019] BLogic context will be cached. jobAppCd:B000001"))); logger.clear(); assertThat(blogicContextSecond, is(blogicContextFirst)); batchJobData.setJobAppCd("B000002"); ApplicationContext anotherContextFirst = applicationContextResolver .resolveApplicationContext(batchJobData); assertThat(logger.getLoggingEvents(), is(asList(info( "[IAL025019] BLogic context will be cached. jobAppCd:B000002")))); logger.clear(); ApplicationContext anotherContextSecond = applicationContextResolver .resolveApplicationContext(batchJobData); assertFalse(logger.getLoggingEvents().contains(info( "[IAL025019] BLogic context will be cached. jobAppCd:B000002"))); assertThat(anotherContextSecond, is(anotherContextFirst)); assertThat(blogicContextSecond, not(anotherContextSecond)); }