Search in sources :

Example 61 with ConfigurableApplicationContext

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

the class EnableAspectJAutoProxyTests method withAnnotationOnArgumentAndCglibProxy.

@Test
public void withAnnotationOnArgumentAndCglibProxy() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class, SampleService.class, LoggingAspect.class);
    SampleService sampleService = ctx.getBean(SampleService.class);
    sampleService.execute(new SampleDto());
    sampleService.execute(new SampleInputBean());
    sampleService.execute((SampleDto) null);
    sampleService.execute((SampleInputBean) null);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Test(org.junit.Test)

Example 62 with ConfigurableApplicationContext

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

the class EnableAspectJAutoProxyTests method withAnnotationOnArgumentAndJdkProxy.

@Test
public void withAnnotationOnArgumentAndJdkProxy() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class, SampleService.class, LoggingAspect.class);
    SampleService sampleService = ctx.getBean(SampleService.class);
    sampleService.execute(new SampleDto());
    sampleService.execute(new SampleInputBean());
    sampleService.execute((SampleDto) null);
    sampleService.execute((SampleInputBean) null);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Test(org.junit.Test)

Example 63 with ConfigurableApplicationContext

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

the class MyPostProcessor method test.

@Test
public void test() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
    assertThat("someDependency was not post processed", ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription(), equalTo("post processed by MyPostProcessor"));
    MyConfig config = ctx.getBean(MyConfig.class);
    assertTrue("Config class was not enhanced", ClassUtils.isCglibProxy(config));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 64 with ConfigurableApplicationContext

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

the class LiveBeansViewTests method registerUnregisterServeralContextsDifferentOrder.

@Test
public void registerUnregisterServeralContextsDifferentOrder() throws MalformedObjectNameException {
    this.environment.setProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, this.name.getMethodName());
    ConfigurableApplicationContext context = createApplicationContext("app");
    ConfigurableApplicationContext childContext = createApplicationContext("child");
    assertEquals(0, searchLiveBeansViewMeans().size());
    LiveBeansView.registerApplicationContext(context);
    assertSingleLiveBeansViewMbean("app");
    LiveBeansView.registerApplicationContext(childContext);
    // Only one MBean
    assertSingleLiveBeansViewMbean("app");
    LiveBeansView.unregisterApplicationContext(context);
    LiveBeansView.unregisterApplicationContext(childContext);
    assertEquals(0, searchLiveBeansViewMeans().size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Test(org.junit.Test)

Example 65 with ConfigurableApplicationContext

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

the class LiveBeansViewTests method registerUnregisterServeralContexts.

@Test
public void registerUnregisterServeralContexts() throws MalformedObjectNameException {
    this.environment.setProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, this.name.getMethodName());
    ConfigurableApplicationContext context = createApplicationContext("app");
    ConfigurableApplicationContext childContext = createApplicationContext("child");
    assertEquals(0, searchLiveBeansViewMeans().size());
    LiveBeansView.registerApplicationContext(context);
    assertSingleLiveBeansViewMbean("app");
    LiveBeansView.registerApplicationContext(childContext);
    // Only one MBean
    assertEquals(1, searchLiveBeansViewMeans().size());
    LiveBeansView.unregisterApplicationContext(childContext);
    // Root context removes it
    assertSingleLiveBeansViewMbean("app");
    LiveBeansView.unregisterApplicationContext(context);
    assertEquals(0, searchLiveBeansViewMeans().size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Test(org.junit.Test)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)177 Test (org.junit.Test)110 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)17 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 DataSource (javax.sql.DataSource)8 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)6 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)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