org.springframework.beans.factory.support.AbstractBeanFactory Java Examples

The following examples show how to use org.springframework.beans.factory.support.AbstractBeanFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testBeanDefinitionWithAbstractClass() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
	try {
		lbf.getBean("test");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertEquals("test", ex.getBeanName());
		assertTrue(ex.getMessage().toLowerCase().contains("abstract"));
	}
}
 
Example #2
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testBeanDefinitionWithAbstractClass() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
	try {
		lbf.getBean("test");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertEquals("test", ex.getBeanName());
		assertTrue(ex.getMessage().toLowerCase().contains("abstract"));
	}
}
 
Example #3
Source File: ServerEndpointExporter.java    From netty-websocket-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    if (!(beanFactory instanceof AbstractBeanFactory)) {
        throw new IllegalArgumentException(
                "AutowiredAnnotationBeanPostProcessor requires a AbstractBeanFactory: " + beanFactory);
    }
    this.beanFactory = (AbstractBeanFactory) beanFactory;
}
 
Example #4
Source File: ConsumerAnnotationScanner.java    From qmq with Apache License 2.0 5 votes vote down vote up
private ListenerHolder(ApplicationContext context,
                       AbstractBeanFactory beanFactory,
                       Object bean,
                       Method method,
                       String subject,
                       String group,
                       String executor,
                       SubscribeParam subscribeParam,
                       String idempotentChecker,
                       String[] filters) {
    this.context = context;
    this.beanFactory = beanFactory;
    this.subject = subject;
    this.group = group;
    this.executorName = executor;
    this.subscribeParam = subscribeParam;
    IdempotentChecker idempotentCheckerBean = null;
    if (idempotentChecker != null && idempotentChecker.length() > 0) {
        idempotentCheckerBean = context.getBean(idempotentChecker, IdempotentChecker.class);
    }

    List<Filter> filterBeans = new ArrayList<>();
    if (filters != null && filters.length > 0) {
        for (int i = 0; i < filters.length; ++i) {
            filterBeans.add(context.getBean(filters[i], Filter.class));
        }
    }
    this.listener = new GeneratedListener(bean, method, idempotentCheckerBean, filterBeans);
}
 
Example #5
Source File: TaskBeanContainer.java    From multi-task with Apache License 2.0 5 votes vote down vote up
/**
 * 注册一个Fetcher
 *
 * @param service
 * @param method
 * @param beanName
 */
private static void registerFetcher(final Object service, final Method method, final String beanName) {
    if (TaskBeanContainer.containsBean(beanName)) {
        throw new TaskBizException("Fetcher bean duplicate for Spring:" + beanName);
    }

    final int paramLen = method.getGenericParameterTypes().length;
    Taskable<?> fetcher = TaskBeanHelper.newFetcher(service, method, beanName, paramLen);

    BeanFactory factory = applicationContext.getAutowireCapableBeanFactory();

    if (factory instanceof DefaultListableBeanFactory) {
        DefaultListableBeanFactory defaultFactory = (DefaultListableBeanFactory) factory;
        defaultFactory.registerSingleton(beanName, fetcher);
        // GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        // beanDefinition.setBeanClass(task.getClass());
        // listFactory.registerBeanDefinition(beanName, beanDefinition);
        LOG.info("DefaultListableBeanFactory Fetcher register: " + beanName);
    } else if (factory instanceof AbstractBeanFactory) {
        AbstractBeanFactory abstFactory = (AbstractBeanFactory) factory;
        abstFactory.registerSingleton(beanName, fetcher);
        LOG.info("AbstractBeanFactory Fetcher register: " + beanName);
    } else {
        container.put(beanName, fetcher);
        LOG.info("LocalContainer Fetcher register: " + beanName);
    }
}
 
Example #6
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testBeanDefinitionWithAbstractClass() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
	try {
		lbf.getBean("test");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertEquals("test", ex.getBeanName());
		assertTrue(ex.getMessage().toLowerCase().contains("abstract"));
	}
}
 
Example #7
Source File: EventMethodArgumentResolver.java    From netty-websocket-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public EventMethodArgumentResolver(AbstractBeanFactory beanFactory) {
    this.beanFactory = beanFactory;
}
 
Example #8
Source File: RequestParamMethodArgumentResolver.java    From netty-websocket-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public RequestParamMethodArgumentResolver(AbstractBeanFactory beanFactory) {
    this.beanFactory = beanFactory;
}
 
Example #9
Source File: PathVariableMethodArgumentResolver.java    From netty-websocket-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public PathVariableMethodArgumentResolver(AbstractBeanFactory beanFactory) {
    this.beanFactory = beanFactory;
}
 
Example #10
Source File: ConsumerAnnotationScanner.java    From qmq with Apache License 2.0 4 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (beanFactory instanceof AbstractBeanFactory) {
        this.beanFactory = (AbstractBeanFactory) beanFactory;
    }
}
 
Example #11
Source File: ConfigurerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {

        if (null == appContexts) {
            return;
        }

        if (null == bn) {
            bn = getBeanName(beanInstance);
            if (null == bn) {
                return;
            }
        }

        if (checkWildcards) {
            configureWithWildCard(bn, beanInstance);
        }

        final String beanName = bn;
        setBeanWiringInfoResolver(new BeanWiringInfoResolver() {
            public BeanWiringInfo resolveWiringInfo(Object instance) {
                if (!beanName.isEmpty()) {
                    return new BeanWiringInfo(beanName);
                }
                return null;
            }
        });

        for (ApplicationContext appContext : appContexts) {
            if (appContext.containsBean(bn)) {
                this.setBeanFactory(appContext.getAutowireCapableBeanFactory());
            }
        }

        try {
            //this will prevent a call into the AbstractBeanFactory.markBeanAsCreated(...)
            //which saves ALL the names into a HashSet.  For URL based configuration,
            //this can leak memory
            if (beanFactory instanceof AbstractBeanFactory) {
                ((AbstractBeanFactory)beanFactory).getMergedBeanDefinition(bn);
            }
            super.configureBean(beanInstance);
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Successfully performed injection.");
            }
        } catch (NoSuchBeanDefinitionException ex) {
            // users often wonder why the settings in their configuration files seem
            // to have no effect - the most common cause is that they have been using
            // incorrect bean ids
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "NO_MATCHING_BEAN_MSG", beanName);
            }
        }
    }