Java Code Examples for org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences()

The following examples show how to use org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences() . 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: XmlBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCircularReferencesWithNotAllowed() {
	DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
	xbf.setAllowCircularReferences(false);
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
	reader.loadBeanDefinitions(REFTYPES_CONTEXT);
	try {
		xbf.getBean("jenny");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
	}
}
 
Example 2
Source File: XmlBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCircularReferencesWithNotAllowed() {
	DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
	xbf.setAllowCircularReferences(false);
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
	reader.loadBeanDefinitions(REFTYPES_CONTEXT);
	try {
		xbf.getBean("jenny");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
	}
}
 
Example 3
Source File: XmlBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCircularReferencesWithNotAllowed() {
	DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
	xbf.setAllowCircularReferences(false);
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
	reader.loadBeanDefinitions(REFTYPES_CONTEXT);
	try {
		xbf.getBean("jenny");
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
	}
}
 
Example 4
Source File: Start.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Start the Start.
 */
public static void main(String[] args) {
    logger.info("Full node running.");
    Args.setParam(args, Constant.MAIN_NET_CONF);
    Args cfgArgs = Args.getInstance();

    load(cfgArgs.getLogbackPath());

    if (cfgArgs.isHelp()) {
        logger.info("Here is the help message.");
        return;
    }

    if (Args.getInstance().isDebug()) {
        logger.info("in debug mode, it won't check cpu time");
    } else {
        logger.info("not in debug mode, it will check cpu time");
    }

    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.setAllowCircularReferences(false);
    GSCApplicationContext context =
            new GSCApplicationContext(beanFactory);
    context.register(DefaultConfig.class);

    context.refresh();
    Application application = ApplicationFactory.create(context);
    shutdown(application);

    RpcApiService rpcApiService = context.getBean(RpcApiService.class);
    application.addService(rpcApiService);
    if (cfgArgs.isWitness()) application.addService(new WitnessService(application, context));
    FullNodeHttpApiService httpApiService = context.getBean(FullNodeHttpApiService.class);
    application.addService(httpApiService);

    if (Args.getInstance().getStorage().getDbVersion() == 2) {
        ConfirmedRpcApiService confirmedRpcApiService = context.getBean(ConfirmedRpcApiService.class);
        application.addService(confirmedRpcApiService);
        ConfirmedHttpApiService confirmedHttpApiService = context.getBean(ConfirmedHttpApiService.class);
        application.addService(confirmedHttpApiService);
    }
    application.initServices(cfgArgs);
    application.startServices();
    application.startup();

    rpcApiService.blockUntilShutdown();
}
 
Example 5
Source File: AbstractRefreshableApplicationContext.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Customize the internal bean factory used by this context.
 * Called for each {@link #refresh()} attempt.
 * <p>The default implementation applies this context's
 * {@linkplain #setAllowBeanDefinitionOverriding "allowBeanDefinitionOverriding"}
 * and {@linkplain #setAllowCircularReferences "allowCircularReferences"} settings,
 * if specified. Can be overridden in subclasses to customize any of
 * {@link DefaultListableBeanFactory}'s settings.
 * @param beanFactory the newly created bean factory for this context
 * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
 * @see DefaultListableBeanFactory#setAllowCircularReferences
 * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
 * @see DefaultListableBeanFactory#setAllowEagerClassLoading
 */
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
	if (this.allowBeanDefinitionOverriding != null) {
		// 默认是 false,不允许覆盖
		beanFactory.setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
	}
	if (this.allowCircularReferences != null) {
		// 默认是 false,不允许循环引用
		beanFactory.setAllowCircularReferences(this.allowCircularReferences);
	}
}
 
Example 6
Source File: AbstractRefreshableApplicationContext.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Customize the internal bean factory used by this context.
 * Called for each {@link #refresh()} attempt.
 * <p>The default implementation applies this context's
 * {@linkplain #setAllowBeanDefinitionOverriding "allowBeanDefinitionOverriding"}
 * and {@linkplain #setAllowCircularReferences "allowCircularReferences"} settings,
 * if specified. Can be overridden in subclasses to customize any of
 * {@link DefaultListableBeanFactory}'s settings.
 * @param beanFactory the newly created bean factory for this context
 * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
 * @see DefaultListableBeanFactory#setAllowCircularReferences
 * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
 * @see DefaultListableBeanFactory#setAllowEagerClassLoading
 */
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
	if (this.allowBeanDefinitionOverriding != null) {
		beanFactory.setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
	}
	if (this.allowCircularReferences != null) {
		beanFactory.setAllowCircularReferences(this.allowCircularReferences);
	}
}
 
Example 7
Source File: AbstractRefreshableApplicationContext.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Customize the internal bean factory used by this context.
 * Called for each {@link #refresh()} attempt.
 * <p>The default implementation applies this context's
 * {@linkplain #setAllowBeanDefinitionOverriding "allowBeanDefinitionOverriding"}
 * and {@linkplain #setAllowCircularReferences "allowCircularReferences"} settings,
 * if specified. Can be overridden in subclasses to customize any of
 * {@link DefaultListableBeanFactory}'s settings.
 * @param beanFactory the newly created bean factory for this context
 * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
 * @see DefaultListableBeanFactory#setAllowCircularReferences
 * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
 * @see DefaultListableBeanFactory#setAllowEagerClassLoading
 */
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
	if (this.allowBeanDefinitionOverriding != null) {
		beanFactory.setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
	}
	if (this.allowCircularReferences != null) {
		beanFactory.setAllowCircularReferences(this.allowCircularReferences);
	}
}
 
Example 8
Source File: AbstractRefreshableApplicationContext.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Customize the internal bean factory used by this context.
 * Called for each {@link #refresh()} attempt.
 * <p>The default implementation applies this context's
 * {@linkplain #setAllowBeanDefinitionOverriding "allowBeanDefinitionOverriding"}
 * and {@linkplain #setAllowCircularReferences "allowCircularReferences"} settings,
 * if specified. Can be overridden in subclasses to customize any of
 * {@link DefaultListableBeanFactory}'s settings.
 * @param beanFactory the newly created bean factory for this context
 * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
 * @see DefaultListableBeanFactory#setAllowCircularReferences
 * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
 * @see DefaultListableBeanFactory#setAllowEagerClassLoading
 */
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
	if (this.allowBeanDefinitionOverriding != null) {
		beanFactory.setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
	}
	if (this.allowCircularReferences != null) {
		beanFactory.setAllowCircularReferences(this.allowCircularReferences);
	}
}