Search in sources :

Example 91 with GenericApplicationContext

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

the class AsyncExecutionTests method asyncMethodsInInterface.

@Test
public void asyncMethodsInInterface() throws Exception {
    originalThreadName = Thread.currentThread().getName();
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class));
    context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
    context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
    context.refresh();
    AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
    asyncTest.doNothing(5);
    asyncTest.doSomething(10);
    Future<String> future = asyncTest.returnSomething(20);
    assertEquals("20", future.get());
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 92 with GenericApplicationContext

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

the class AsyncExecutionTests method asyncClassWithInterface.

@Test
public void asyncClassWithInterface() throws Exception {
    originalThreadName = Thread.currentThread().getName();
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class));
    context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
    context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
    context.refresh();
    RegularInterface asyncTest = context.getBean("asyncTest", RegularInterface.class);
    asyncTest.doSomething(10);
    Future<String> future = asyncTest.returnSomething(20);
    assertEquals("20", future.get());
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 93 with GenericApplicationContext

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

the class AsyncExecutionTests method asyncMethodsWithQualifier.

@Test
public void asyncMethodsWithQualifier() throws Exception {
    originalThreadName = Thread.currentThread().getName();
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodWithQualifierBean.class));
    context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
    context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
    context.registerBeanDefinition("e0", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
    context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
    context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
    context.refresh();
    AsyncMethodWithQualifierBean asyncTest = context.getBean("asyncTest", AsyncMethodWithQualifierBean.class);
    asyncTest.doNothing(5);
    asyncTest.doSomething(10);
    Future<String> future = asyncTest.returnSomething(20);
    assertEquals("20", future.get());
    Future<String> future2 = asyncTest.returnSomething2(30);
    assertEquals("30", future2.get());
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test)

Example 94 with GenericApplicationContext

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

the class AsyncExecutionTests method asyncInterfaceWithPostProcessor.

@Test
public void asyncInterfaceWithPostProcessor() throws Exception {
    originalThreadName = Thread.currentThread().getName();
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class));
    context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
    context.refresh();
    AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
    asyncTest.doSomething(10);
    Future<String> future = asyncTest.returnSomething(20);
    assertEquals("20", future.get());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 95 with GenericApplicationContext

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

the class AsyncExecutionTests method asyncClassListener.

@Test
public void asyncClassListener() throws Exception {
    originalThreadName = Thread.currentThread().getName();
    listenerCalled = 0;
    listenerConstructed = 0;
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassListener.class));
    context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
    context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
    context.refresh();
    context.close();
    Thread.sleep(1000);
    assertEquals(2, listenerCalled);
    assertEquals(1, listenerConstructed);
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)245 Test (org.junit.Test)190 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)80 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)38 BeanCreationException (org.springframework.beans.factory.BeanCreationException)26 ClassPathResource (org.springframework.core.io.ClassPathResource)19 TestBean (org.springframework.tests.sample.beans.TestBean)17 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)15 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)12 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeansException (org.springframework.beans.BeansException)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 HashMap (java.util.HashMap)7 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Before (org.junit.Before)6 Properties (java.util.Properties)5 EntityManager (javax.persistence.EntityManager)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5