當前位置: 首頁>>代碼示例>>Java>>正文


Java AutowireCapableBeanFactory類代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.AutowireCapableBeanFactory的典型用法代碼示例。如果您正苦於以下問題:Java AutowireCapableBeanFactory類的具體用法?Java AutowireCapableBeanFactory怎麽用?Java AutowireCapableBeanFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AutowireCapableBeanFactory類屬於org.springframework.beans.factory.config包,在下文中一共展示了AutowireCapableBeanFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public void init(ServletConfig config) throws ServletException {
    try {
        WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
        final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
        beanFactory.autowireBean(this);
    }
    catch (Exception e) {
        logger.error("Error initializing ShibbolethExtAuthnHandler", e);
    }
}
 
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:11,代碼來源:ShibbolethExtAuthnHandler.java

示例2: buildCommandHandlersRegistry

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage,
                                                                       final ApplicationContext context) {

    final Map<String, CommandHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class));

    CommandHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (CommandHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest(), currentHandler);
    }

    return registry;
}
 
開發者ID:sem2nawara,項目名稱:cqrs-es-kafka,代碼行數:19,代碼來源:CommandHandlerUtils.java

示例3: testAutowireWithSatisfiedJavaBeanDependency

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithSatisfiedJavaBeanDependency() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "Rod");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("rod", bd);
	assertEquals(1, lbf.getBeanDefinitionCount());
	// Depends on age, name and spouse (TestBean)
	Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
	assertEquals(1, lbf.getBeanDefinitionCount());
	DependenciesBean kerry = (DependenciesBean) registered;
	TestBean rod = (TestBean) lbf.getBean("rod");
	assertSame(rod, kerry.getSpouse());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:DefaultListableBeanFactoryTests.java

示例4: testAutowireWithTwoMatchesForConstructorDependency

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithTwoMatchesForConstructorDependency() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	lbf.registerBeanDefinition("rod", bd);
	RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
	lbf.registerBeanDefinition("rod2", bd2);
	try {
		lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertTrue(ex.getMessage().contains("rod"));
		assertTrue(ex.getMessage().contains("rod2"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:DefaultListableBeanFactoryTests.java

示例5: testAutowireWithUnsatisfiedConstructorDependency

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithUnsatisfiedConstructorDependency() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue(new PropertyValue("name", "Rod"));
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("rod", bd);
	assertEquals(1, lbf.getBeanDefinitionCount());
	try {
		lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
		fail("Should have unsatisfied constructor dependency on SideEffectBean");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:DefaultListableBeanFactoryTests.java

示例6: testAutowireBeanByTypeWithTwoMatches

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoMatches() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
	lbf.registerBeanDefinition("test", bd);
	lbf.registerBeanDefinition("spouse", bd2);
	try {
		lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertTrue(ex.getMessage().contains("test"));
		assertTrue(ex.getMessage().contains("spouse"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:DefaultListableBeanFactoryTests.java

示例7: testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
	lbf.registerBeanDefinition("test", bd);
	lbf.registerBeanDefinition("spouse", bd2);
	try {
		lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertTrue(ex.getMessage().contains("test"));
		assertTrue(ex.getMessage().contains("spouse"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:DefaultListableBeanFactoryTests.java

示例8: testAutowireBeanByTypeWithTwoPrimaryCandidates

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoPrimaryCandidates() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPrimary(true);
	RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
	bd2.setPrimary(true);
	lbf.registerBeanDefinition("test", bd);
	lbf.registerBeanDefinition("spouse", bd2);

	try {
		lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertNotNull("Exception should have cause", ex.getCause());
		assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass());
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:DefaultListableBeanFactoryTests.java

示例9: testAutowireBeanByTypeWithIdenticalPriorityCandidates

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class);
	lbf.registerBeanDefinition("test", bd);
	lbf.registerBeanDefinition("spouse", bd2);

	try {
		lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertNotNull("Exception should have cause", ex.getCause());
		assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass());
		assertTrue(ex.getMessage().contains("5")); // conflicting priority
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:DefaultListableBeanFactoryTests.java

示例10: getInstance

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public LdapUserManager getInstance(final LdapUserManager.Provider provider) {
    LdapUserManager ldapUserManager;
    if (provider == LdapUserManager.Provider.MICROSOFTAD) {
        ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.MICROSOFTAD);
        if (ldapUserManager == null) {
            ldapUserManager = new ADLdapUserManagerImpl();
            applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
            ldapUserManagerMap.put(LdapUserManager.Provider.MICROSOFTAD, ldapUserManager);
        }
    } else {
        //defaults to openldap
        ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.OPENLDAP);
        if (ldapUserManager == null) {
            ldapUserManager = new OpenLdapUserManagerImpl();
            applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
            ldapUserManagerMap.put(LdapUserManager.Provider.OPENLDAP, ldapUserManager);
        }
    }
    return ldapUserManager;
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:21,代碼來源:LdapUserManagerFactory.java

示例11: buildCommandHandlersRegistry

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage,
                                                                       final ApplicationContext context) {

    final Map<String, CommandHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class));

    CommandHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (CommandHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest().getName(), currentHandler);
    }

    return registry;
}
 
開發者ID:sem2nawara,項目名稱:acme-solution,代碼行數:19,代碼來源:CommandHandlerUtils.java

示例12: buildEventHandlersRegistry

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public static Map<String, EventHandler> buildEventHandlersRegistry(final String basePackage,
                                                                   final ApplicationContext context) {

    final Map<String, EventHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(EventHandler.class));

    EventHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (EventHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest(), currentHandler);
    }

    return registry;
}
 
開發者ID:sem2nawara,項目名稱:acme-solution,代碼行數:19,代碼來源:EventHandlerUtils.java

示例13: installGenerator

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private void installGenerator(final URI pluginId, final Version version, final PluginVO plugin,
                              final ClassPathXmlApplicationContext cax,
                              final Generator<GeneratorConfiguration, GeneratorStatistics> generator) {
    cax.getAutowireCapableBeanFactory()
            .autowireBeanProperties(generator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);

    if (generator.getConfiguration() == null) {
        GeneratorConfiguration generatorConfiguration = generator.newConfiguration();
        generator.setConfiguration(generatorConfiguration);
    }

    if (LifecyclePhase.NOT_INSTALLED.toString().equals(plugin.getState()))
        generator.install(true);
    else
        generator.install(false);

    pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INSTALLED.toString());

    generator.initialize();
    generators.put(generator.getId(), generator);
    contexts.put(generator.getId(), cax);
    logger.info("registered plugin " + generator.getSourceType());
    pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INITIALIZED.toString());
}
 
開發者ID:major2015,項目名稱:easyrec_major,代碼行數:25,代碼來源:PluginRegistry.java

示例14: testContextConfiguration

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private void testContextConfiguration(String profile, String springProfile) {
    GenericXmlApplicationContext context = createContext(profile, springProfile);
    AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory();

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    Collection<Class<?>> descendants = classFinder.getDescendants(Object.class, "com.hotwire.test.steps");

    List<Throwable> throwables = new ArrayList<>();
    for (Class<?> clazz : descendants) {
        if (Utils.isInstantiable(clazz) & !clazz.isEnum()) {
            context.registerBeanDefinition(clazz.getName(),
                    BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition());
            try {
                factory.getBean(clazz.getName());
            }
            catch (Throwable t) {
                while (t.getCause() != null) {
                    t = t.getCause();
                }
                System.err.println(t.getMessage());
                throwables.add(t);
            }
        }
    }
    assertThat(throwables)
            .as("List of throwables should be empty!")
            .isEmpty();
}
 
開發者ID:HotwireDotCom,項目名稱:bdd-test-automation-for-mobile,代碼行數:31,代碼來源:ContextConfigurationTest.java

示例15: doGet

import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private synchronized Object doGet(final String className) {
    // Check again for the cache here, inside the sync method
    Object bean = beans.get(className);
    if (bean != null) {
        return bean;
    }
    try {
        AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
        Class<?> beanClass = Class.forName(className);
        bean = factory.createBean(beanClass, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
        factory.initializeBean(bean, beanClass.getSimpleName() + "#" + System.identityHashCode(bean));
        beans.put(className, bean);
        return bean;
    } catch (Exception e) {
        throw new IllegalArgumentException("Couldn't instantiate class " + className, e);
    }
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:18,代碼來源:CustomObjectHandlerImpl.java


注:本文中的org.springframework.beans.factory.config.AutowireCapableBeanFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。