/** * Close the view bean factory on context shutdown. */ @Override public void destroy() throws BeansException { if (this.cachedFactory != null) { this.cachedFactory.close(); } }
@Override public void contextDestroyed(ServletContextEvent sce) { this.applicationContext.close(); } }
/** * This implementation closes the Spring ApplicationContext. */ @Override public void stop() { logger.debug("Stopping SpringContextResourceAdapter"); if (this.applicationContext != null) { this.applicationContext.close(); } }
@After public void closeContext() { if (this.context != null) { this.context.close(); } }
@After public void closeContext() { if (context != null) { context.close(); } }
@After public void closeContext() { if (this.context != null) { this.context.close(); } }
@After public void closeContext() { if (this.ctx != null) { this.ctx.close(); } }
@After public void closeContext() { if (this.context != null) { this.context.close(); } }
@After public void closeContext() { if (this.context != null) { this.context.close(); } }
@After public void close() { if (this.ctx != null) { this.ctx.close(); } }
@After public void tearDown() { if (ctx != null) { ctx.close(); } }
@Test public void testAutodetectNoMBeans() throws Exception { ConfigurableApplicationContext ctx = load("autodetectNoMBeans.xml"); try { ctx.getBean("exporter"); } finally { ctx.close(); } }
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
@Test // SPR-11692 @SuppressWarnings("unchecked") public void expressionIsCacheBasedOnActualMethod() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(SharedConfig.class, Spr11692Config.class); BaseDao<User> userDao = (BaseDao<User>) context.getBean("userDao"); BaseDao<Order> orderDao = (BaseDao<Order>) context.getBean("orderDao"); userDao.persist(new User("1")); orderDao.persist(new Order("2")); context.close(); }
private void assertApplicationContextLoadsAndContainsFooString(MergedContextConfiguration mergedConfig) throws Exception { ApplicationContext applicationContext = loader.loadContext(mergedConfig); assertNotNull(applicationContext); assertEquals("foo", applicationContext.getBean(String.class)); assertTrue(applicationContext instanceof ConfigurableApplicationContext); ((ConfigurableApplicationContext) applicationContext).close(); }
@Test public void invokedAsynchronously() { ConfigurableApplicationContext context = initContext( new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); ITestBean testBean = context.getBean("target", ITestBean.class); testBean.test(); Thread mainThread = Thread.currentThread(); testBean.await(3000); Thread asyncThread = testBean.getThread(); assertNotSame(mainThread, asyncThread); context.close(); }
@Test public void emptyConfigSupport() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertNotNull(ci.getCacheResolver()); assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass()); assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager()); context.close(); }
@Test // SPR-6354 public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass()); assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder")); StopWatch sw = new StopWatch(); sw.start("lazyScheduler"); context.close(); sw.stop(); assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500); }
@Test // SPR-6354 public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass()); assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder")); StopWatch sw = new StopWatch(); sw.start("lazyScheduler"); context.close(); sw.stop(); assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500); }