Search in sources :

Example 31 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project ignite by apache.

the class GridTestMain method main.

/**
 * Main method.
 *
 * @param args Parameters.
 * @throws IgniteCheckedException If failed.
 */
public static void main(String[] args) throws Exception {
    BeanFactory ctx = new ClassPathXmlApplicationContext("org/apache/ignite/loadtests/colocation/spring-colocation.xml");
    // Initialize Spring factory.
    try (Ignite g = G.start((IgniteConfiguration) ctx.getBean("grid.cfg"))) {
        final IgniteCache<GridTestKey, Long> cache = g.cache("partitioned");
        assert cache != null;
        // Uncomment if you plan to load cache using AccentureCacheStore.
        // generateAndLoad();
        // Uncomment if you plan to load cache from cache store.
        // Note that you could also do this automatically from lifecycle bean.
        // To configure lifecycle bean, uncomment 'lifecycleBeans' property in
        // spring-accenture.xml file.
        loadFromStore(cache);
        X.println("Number of entries in cache: " + cache.size());
        colocateJobs();
    // localPoolRun();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) Ignite(org.apache.ignite.Ignite)

Example 32 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project grails-core by grails.

the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.

@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
    final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
    BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
    GrailsPluginManager pluginManager = null;
    if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
        HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
        BeanFactory parent = beanFactory.getParentBeanFactory();
        if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
            pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
        }
    }
    if (pluginManager != null) {
        List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
        for (TypeFilter typeFilter : typeFilters) {
            scanner.addIncludeFilter(typeFilter);
        }
    }
    return scanner;
}
Also used : ClassPathBeanDefinitionScanner(org.springframework.context.annotation.ClassPathBeanDefinitionScanner) GrailsPluginManager(grails.plugins.GrailsPluginManager) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) TypeFilter(org.springframework.core.type.filter.TypeFilter) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory)

Example 33 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testCustomPrototypeTargetSource.

@Test
public void testCustomPrototypeTargetSource() throws Exception {
    CountingTestBean.count = 0;
    BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
    ITestBean test = (ITestBean) bf.getBean("prototypeTest");
    assertTrue(AopUtils.isAopProxy(test));
    Advised advised = (Advised) test;
    assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
    assertEquals("Rod", test.getName());
    // Check that references survived prototype creation
    assertEquals("Kerry", test.getSpouse().getName());
    assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
    CountingTestBean.count = 0;
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) BeanFactory(org.springframework.beans.factory.BeanFactory) PrototypeTargetSource(org.springframework.aop.target.PrototypeTargetSource) Test(org.junit.Test)

Example 34 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testCommonInterceptorAndAdvisor.

/**
	 * Check that we can provide a common interceptor that will
	 * appear in the chain before "specific" interceptors,
	 * which are sourced from matching advisors
	 */
@Test
public void testCommonInterceptorAndAdvisor() throws Exception {
    BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
    ITestBean test1 = (ITestBean) bf.getBean("test1");
    assertTrue(AopUtils.isAopProxy(test1));
    Lockable lockable1 = (Lockable) test1;
    NopInterceptor nop1 = (NopInterceptor) bf.getBean("nopInterceptor");
    NopInterceptor nop2 = (NopInterceptor) bf.getBean("pointcutAdvisor", Advisor.class).getAdvice();
    ITestBean test2 = (ITestBean) bf.getBean("test2");
    Lockable lockable2 = (Lockable) test2;
    // Locking should be independent; nop is shared
    assertFalse(lockable1.locked());
    assertFalse(lockable2.locked());
    // equals 2 calls on shared nop, because it's first and sees calls
    // against the Lockable interface introduced by the specific advisor
    assertEquals(2, nop1.getCount());
    assertEquals(0, nop2.getCount());
    lockable1.lock();
    assertTrue(lockable1.locked());
    assertFalse(lockable2.locked());
    assertEquals(5, nop1.getCount());
    assertEquals(0, nop2.getCount());
    PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) bf.getBean("packageVisibleMethod");
    assertEquals(5, nop1.getCount());
    assertEquals(0, nop2.getCount());
    packageVisibleMethod.doSomething();
    assertEquals(6, nop1.getCount());
    assertEquals(1, nop2.getCount());
    assertTrue(packageVisibleMethod instanceof Lockable);
    Lockable lockable3 = (Lockable) packageVisibleMethod;
    lockable3.lock();
    assertTrue(lockable3.locked());
    lockable3.unlock();
    assertFalse(lockable3.locked());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) Lockable(test.mixin.Lockable) Test(org.junit.Test)

Example 35 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testWithOptimizedProxy.

@Test
public void testWithOptimizedProxy() throws Exception {
    BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);
    ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
    assertTrue(AopUtils.isAopProxy(testBean));
    CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");
    testBean.setAge(23);
    testBean.getAge();
    assertEquals("Incorrect number of calls to proxy", 2, beforeAdvice.getCalls());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) CountingBeforeAdvice(org.springframework.tests.aop.advice.CountingBeforeAdvice) Test(org.junit.Test)

Aggregations

BeanFactory (org.springframework.beans.factory.BeanFactory)62 Test (org.junit.Test)28 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)17 ITestBean (org.springframework.tests.sample.beans.ITestBean)11 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)10 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 FactoryBean (org.springframework.beans.factory.FactoryBean)4 SmartFactoryBean (org.springframework.beans.factory.SmartFactoryBean)4 CallCountingTransactionManager (org.springframework.tests.transaction.CallCountingTransactionManager)4 DataSource (javax.sql.DataSource)3 Ignite (org.apache.ignite.Ignite)3 TestInjectionLifecycleBean (org.apache.ignite.TestInjectionLifecycleBean)3 BeansException (org.springframework.beans.BeansException)3 BeanNotOfRequiredTypeException (org.springframework.beans.factory.BeanNotOfRequiredTypeException)3 HierarchicalBeanFactory (org.springframework.beans.factory.HierarchicalBeanFactory)3