Search in sources :

Example 11 with SimpleMapScope

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

the class ComponentScanWithBasePackagesAndValueAlias method withScopedProxyThroughRegex.

@Test
public void withScopedProxyThroughRegex() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughRegex.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) Test(org.junit.Test)

Example 12 with SimpleMapScope

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

the class ComponentScanWithBasePackagesAndValueAlias method withScopedProxyThroughAspectJPattern.

@Test
public void withScopedProxyThroughAspectJPattern() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 SimpleMapScope (org.springframework.tests.context.SimpleMapScope)12 FooService (example.scannable.FooService)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 ScopedProxyTestBean (example.scannable.ScopedProxyTestBean)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 ITestBean (org.springframework.tests.sample.beans.ITestBean)3 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 TestBean (org.springframework.tests.sample.beans.TestBean)2 ArrayList (java.util.ArrayList)1 ScopedObject (org.springframework.aop.scope.ScopedObject)1 FactoryMethodComponent (org.springframework.context.annotation4.FactoryMethodComponent)1