Search in sources :

Example 16 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.

the class EnableCachingTests method emptyConfigSupport.

@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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) NoOpCacheManager(org.springframework.cache.support.NoOpCacheManager) CacheManager(org.springframework.cache.CacheManager) CacheInterceptor(org.springframework.cache.interceptor.CacheInterceptor) Test(org.junit.Test)

Example 17 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.

the class ExpressionCachingIntegrationTests method expressionIsCacheBasedOnActualMethod.

// SPR-11692
@Test
@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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 18 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class Restarter method stop.

/**
	 * Stop the application.
	 * @throws Exception in case of errors
	 */
protected void stop() throws Exception {
    this.logger.debug("Stopping application");
    this.stopLock.lock();
    try {
        for (ConfigurableApplicationContext context : this.rootContexts) {
            context.close();
            this.rootContexts.remove(context);
        }
        cleanupCaches();
        if (this.forceReferenceCleanup) {
            forceReferenceCleanup();
        }
    } finally {
        this.stopLock.unlock();
    }
    System.gc();
    System.runFinalization();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext)

Example 19 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class AbstractDevToolsDataSourceAutoConfigurationTests method singleManuallyConfiguredDataSourceIsNotClosed.

@Test
public void singleManuallyConfiguredDataSourceIsNotClosed() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class, SingleDataSourceConfiguration.class);
    DataSource dataSource = context.getBean(DataSource.class);
    Statement statement = configureDataSourceBehaviour(dataSource);
    verify(statement, times(0)).execute("SHUTDOWN");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 20 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project spring-boot by spring-projects.

the class AbstractDevToolsDataSourceAutoConfigurationTests method multipleDataSourcesAreIgnored.

@Test
public void multipleDataSourcesAreIgnored() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class, MultipleDataSourcesConfiguration.class);
    Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
    for (DataSource dataSource : dataSources) {
        Statement statement = configureDataSourceBehaviour(dataSource);
        verify(statement, times(0)).execute("SHUTDOWN");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)162 Test (org.junit.Test)108 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)15 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 DataSource (javax.sql.DataSource)8 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)6 Statement (java.sql.Statement)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4 RedisRunner (org.redisson.RedisRunner)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4