java类org.springframework.beans.factory.config.AutowireCapableBeanFactory的实例源码

ShibbolethExtAuthnHandler.java 文件源码 项目:e-identification-tupas-idp-public 阅读 28 收藏 0 点赞 0 评论 0
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);
    }
}
CommandHandlerUtils.java 文件源码 项目:cqrs-es-kafka 阅读 18 收藏 0 点赞 0 评论 0
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;
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@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());
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 31 收藏 0 点赞 0 评论 0
@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"));
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@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
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@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"));
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@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"));
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 19 收藏 0 点赞 0 评论 0
@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());
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:spring4-understanding 阅读 25 收藏 0 点赞 0 评论 0
@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
    }
}
LdapUserManagerFactory.java 文件源码 项目:cosmic 阅读 21 收藏 0 点赞 0 评论 0
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;
}
CommandHandlerUtils.java 文件源码 项目:acme-solution 阅读 26 收藏 0 点赞 0 评论 0
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;
}
EventHandlerUtils.java 文件源码 项目:acme-solution 阅读 22 收藏 0 点赞 0 评论 0
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;
}
PluginRegistry.java 文件源码 项目:easyrec_major 阅读 21 收藏 0 点赞 0 评论 0
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());
}
CustomObjectHandlerImpl.java 文件源码 项目:OpenCyclos 阅读 22 收藏 0 点赞 0 评论 0
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);
    }
}
GoogleAnalyticsTag.java 文件源码 项目:metaworks_framework 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();
    String webPropertyId = getWebPropertyId();

    if (webPropertyId == null) {
        ServletContext sc = ((PageContext) getJspContext()).getServletContext();
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    }

    if (webPropertyId.equals("UA-XXXXXXX-X")) {
        LOG.warn("googleAnalytics.webPropertyId has not been overridden in a custom property file. Please set this in order to properly use the Google Analytics tag");
    }

    out.println(analytics(webPropertyId, order));
    super.doTag();
}
SpaceRemotingServiceExporter.java 文件源码 项目:xap-openspaces 阅读 23 收藏 0 点赞 0 评论 0
private void autowireArguments(Object service, Object[] args) {
    if (disableAutowiredArguments) {
        return;
    }
    if (args == null) {
        return;
    }
    if (shouldAutowire(service)) {
        for (Object arg : args) {
            if (arg == null) {
                continue;
            }
            AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
            beanFactory.autowireBeanProperties(arg, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
            beanFactory.initializeBean(arg, arg.getClass().getName());
        }
    }
}
GoogleAnalyticsTag.java 文件源码 项目:SparkCommerce 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();
    String webPropertyId = getWebPropertyId();

    if (webPropertyId == null) {
        ServletContext sc = ((PageContext) getJspContext()).getServletContext();
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    }

    if (webPropertyId.equals("UA-XXXXXXX-X")) {
        LOG.warn("googleAnalytics.webPropertyId has not been overridden in a custom property file. Please set this in order to properly use the Google Analytics tag");
    }

    out.println(analytics(webPropertyId, order));
    super.doTag();
}
GoogleAnalyticsTag.java 文件源码 项目:SparkCore 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();
    String webPropertyId = getWebPropertyId();

    if (webPropertyId == null) {
        ServletContext sc = ((PageContext) getJspContext()).getServletContext();
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    }

    if (webPropertyId.equals("UA-XXXXXXX-X")) {
        LOG.warn("googleAnalytics.webPropertyId has not been overridden in a custom property file. Please set this in order to properly use the Google Analytics tag");
    }

    out.println(analytics(webPropertyId, order));
    super.doTag();
}
CPESessionContextIntegrationFilter.java 文件源码 项目:eHMP 阅读 20 收藏 0 点赞 0 评论 0
private void autowireAndInitialize(ServletRequest req, Map<String, Object> contexts) {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
    AutowireCapableBeanFactory autowirer = appContext.getAutowireCapableBeanFactory();
    for (Map.Entry<String,Object> entry : contexts.entrySet()) {
        Object context = entry.getValue();
        autowirer.autowireBean(context);
        try {
            if (context instanceof InitializingBean) {
                ((InitializingBean) context).afterPropertiesSet();
            }
        } catch (Exception e) {
            logger.warn("Invocation of init method failed of context: " + entry.getKey(), e);
        }

    }
}
StorageManager.java 文件源码 项目:concurrent 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 初始化类资源的存储空间
 * @param clz 类实例
 * @return
 */
private Storage initializeStorage(Class clz) {
    ResourceDefinition definition = this.definitions.get(clz);
    if (definition == null) {
        FormattingTuple message = MessageFormatter.format("静态资源[{}]的信息定义不存在,可能是配置缺失", clz.getSimpleName());
        logger.error(message.getMessage());
        throw new IllegalStateException(message.getMessage());
    }
    AutowireCapableBeanFactory beanFactory = this.applicationContext.getAutowireCapableBeanFactory();
    Storage storage = beanFactory.createBean(Storage.class);

    Storage prev = storages.putIfAbsent(clz, storage);
    if (prev == null) {
        storage.initialize(definition);
    }
    return prev == null ? storage : prev;
}
DatabaseMigrateContextListener.java 文件源码 项目:ix3 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext());
    AutowireCapableBeanFactory autowireCapableBeanFactory=webApplicationContext.getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    //Permitirmos varias "locations" en el parámetro separados por "\n"
    String[] rawLocations = (servletContextEvent.getServletContext().getInitParameter("databasemigration.location")+"").split("\\n");
    List<String> locations = new ArrayList<String>();
    for(String location : rawLocations) {
        if ((location!=null) && (location.trim().isEmpty()==false)) {
            locations.add(location);
        }
    }

    databaseMigration.migrate(locations);
}
PluginRegistry.java 文件源码 项目:easyrec-PoC 阅读 22 收藏 0 点赞 0 评论 0
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());
}
DefaultListableBeanFactoryTests.java 文件源码 项目:class-guard 阅读 22 收藏 0 点赞 0 评论 0
@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());
}
DefaultListableBeanFactoryTests.java 文件源码 项目:class-guard 阅读 24 收藏 0 点赞 0 评论 0
@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().indexOf("rod") != -1);
        assertTrue(ex.getMessage().indexOf("rod2") != -1);
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:class-guard 阅读 25 收藏 0 点赞 0 评论 0
@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
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:class-guard 阅读 29 收藏 0 点赞 0 评论 0
@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().indexOf("test") != -1);
        assertTrue(ex.getMessage().indexOf("spouse") != -1);
    }
}
DefaultListableBeanFactoryTests.java 文件源码 项目:class-guard 阅读 25 收藏 0 点赞 0 评论 0
@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().indexOf("test") != -1);
        assertTrue(ex.getMessage().indexOf("spouse") != -1);
    }
}
PluginRegistry.java 文件源码 项目:easyrec 阅读 28 收藏 0 点赞 0 评论 0
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());
}
ModuleBasedFilter.java 文件源码 项目:cloudstack 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String module = filterConfig.getInitParameter("module");
    CloudStackSpringContext context = (CloudStackSpringContext)filterConfig.getServletContext().getAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY);

    if (context == null)
        return;

    ApplicationContext applicationContext = context.getApplicationContextForWeb(module);
    if (applicationContext != null) {
        AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
        if (factory != null) {
            factory.autowireBean(this);
            enabled = true;
        }
    }
}
LdapUserManagerFactory.java 文件源码 项目:cloudstack 阅读 23 收藏 0 点赞 0 评论 0
public LdapUserManager getInstance(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;
}


问题


面经


文章

微信
公众号

扫码关注公众号