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


Java GenericBeanDefinition.setScope方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.support.GenericBeanDefinition.setScope方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericBeanDefinition.setScope方法的具體用法?Java GenericBeanDefinition.setScope怎麽用?Java GenericBeanDefinition.setScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.support.GenericBeanDefinition的用法示例。


在下文中一共展示了GenericBeanDefinition.setScope方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createBeanDefinition

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
private static BeanDefinition createBeanDefinition(ComponentDefinition componentDefinition) {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();

    beanDefinition.setBeanClassName(componentDefinition.getComponentClass());
    beanDefinition.setScope(getScope(componentDefinition.getScope()));
    beanDefinition.setAutowireCandidate(true);
    beanDefinition.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
    beanDefinition.setDependsOn(componentDefinition.getDependsOn());
    beanDefinition.setLazyInit(componentDefinition.isLazyInit());

    ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
    for (Object value : componentDefinition.getConstructorArguments()) {
        constructorArgumentValues.addIndexedArgumentValue(constructorArgumentValues.getArgumentCount(), value);
    }
    beanDefinition.setConstructorArgumentValues(constructorArgumentValues);

    MutablePropertyValues propertyValues = new MutablePropertyValues();
    for (PropertyValue propertyValue : componentDefinition.getPropertyValues()) {
        propertyValues.add(propertyValue.getName(), propertyValue.getValue());
    }
    beanDefinition.setPropertyValues(propertyValues);

    return beanDefinition;
}
 
開發者ID:Indoqa,項目名稱:indoqa-spring,代碼行數:25,代碼來源:DynamicApplicationContextBuilder.java

示例2: createApplicationServlet

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * Creates a Servlet bean definition for the given JAX-RS application
 *
 * @param applicationClass
 * @param path
 * @return a Servlet bean definition for the given JAX-RS application
 */
private GenericBeanDefinition createApplicationServlet(Class<? extends Application> applicationClass, String path) {
    GenericBeanDefinition applicationServletBean = new GenericBeanDefinition();
    applicationServletBean.setFactoryBeanName(ResteasyApplicationBuilder.BEAN_NAME);
    applicationServletBean.setFactoryMethodName("build");

    Set<Class<?>> resources = allResources;

    ConstructorArgumentValues values = new ConstructorArgumentValues();
    values.addIndexedArgumentValue(0, applicationClass.getName());
    values.addIndexedArgumentValue(1, path);
    values.addIndexedArgumentValue(2, resources);
    values.addIndexedArgumentValue(3, providers);
    applicationServletBean.setConstructorArgumentValues(values);

    applicationServletBean.setAutowireCandidate(false);
    applicationServletBean.setScope("singleton");

    return applicationServletBean;
}
 
開發者ID:paypal,項目名稱:resteasy-spring-boot,代碼行數:27,代碼來源:ResteasyEmbeddedServletInitializer.java

示例3: createAndRegisterBean

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
private void createAndRegisterBean(BeanDefinitionRegistry registry,
		String beanName,  Class<?>[] interfaces, ResourceScriptSource rs,
		long refreshCheckDelay) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setFactoryBeanName(DEFAULT_SCRIPT_FACTORY_NAME + beanName);
	beanDefinition.setFactoryMethodName(DEFAULT_SCRIPT_FACTORY_METHOD_NAME);
	beanDefinition.getConstructorArgumentValues().clear();
	beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, rs);
	beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
	beanDefinition.setAutowireCandidate(true);
	beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	beanDefinition.setAttribute(
			ScriptFactoryPostProcessor.REFRESH_CHECK_DELAY_ATTRIBUTE, refreshCheckDelay);		
    registry.registerBeanDefinition(beanName,beanDefinition);		

}
 
開發者ID:valliappanr,項目名稱:refreshable-beans,代碼行數:17,代碼來源:SpringContextWrapper.java

示例4: registerAspect

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * register aspectJ for disconf get request
 *
 * @param registry
 */
private void registerAspect(BeanDefinitionRegistry registry) {

    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(DisconfAspectJ.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.setAbstract(false);
    beanDefinition.setAutowireCandidate(true);
    beanDefinition.setScope("singleton");

    registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
 
開發者ID:ningyu1,項目名稱:disconf-client-ext,代碼行數:17,代碼來源:DisconfMgrBeanExt.java

示例5: registerPrototype

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * Register a prototype bean with the underlying bean factory.
 * <p>For more advanced needs, register with the underlying BeanFactory directly.
 * @see #getDefaultListableBeanFactory
 */
public void registerPrototype(String name, Class<?> clazz) throws BeansException {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
	bd.setBeanClass(clazz);
	getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:StaticApplicationContext.java

示例6: getTargetSource

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
@Override
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
	AbstractBeanFactoryBasedTargetSource targetSource =
			createBeanFactoryBasedTargetSource(beanClass, beanName);
	if (targetSource == null) {
		return null;
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
	}

	DefaultListableBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);

	// We need to override just this bean definition, as it may reference other beans
	// and we're happy to take the parent's definition for those.
	// Always use prototype scope if demanded.
	BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
	GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
	if (isPrototypeBased()) {
		bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	}
	internalBeanFactory.registerBeanDefinition(beanName, bdCopy);

	// Complete configuring the PrototypeTargetSource.
	targetSource.setTargetBeanName(beanName);
	targetSource.setBeanFactory(internalBeanFactory);

	return targetSource;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:AbstractBeanFactoryBasedTargetSourceCreator.java

示例7: testNonSingletonSteps

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
@Test(expectedExceptions = FatalBeanException.class)
public void testNonSingletonSteps() {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("emptyContext.xml");
	ConfigurableListableBeanFactory factory = context.getBeanFactory();

	GenericBeanDefinition definition = new GenericBeanDefinition();
	definition.setBeanClass(DuplicateGivenBeanA.class);
	definition.setLazyInit(false);
	definition.setScope("prototype");

	BeanDefinitionRegistry registry = BeanDefinitionRegistry.class.cast(factory);
	registry.registerBeanDefinition(DuplicateGivenBeanA.class.getName(), definition);
	process(context, new DuplicateGivenBeanA());
}
 
開發者ID:qas-guru,項目名稱:martini-core,代碼行數:15,代碼來源:StepsAnnotationProcessorTest.java

示例8: initApplicationContext

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
private ConfigurablePortletApplicationContext initApplicationContext(String scope) {
	MockServletContext sc = new MockServletContext();
	GenericWebApplicationContext rac = new GenericWebApplicationContext(sc);
	rac.refresh();
	PortletContext pc = new ServletWrappingPortletContext(sc);
	StaticPortletApplicationContext ac = new StaticPortletApplicationContext();
	ac.setParent(rac);
	ac.setPortletContext(pc);
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(DerivedTestBean.class);
	bd.setScope(scope);
	ac.registerBeanDefinition(NAME, bd);
	ac.refresh();
	return ac;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:PortletApplicationContextScopeTests.java

示例9: initApplicationContext

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
private WebApplicationContext initApplicationContext(String scope) {
	MockServletContext sc = new MockServletContext();
	GenericWebApplicationContext ac = new GenericWebApplicationContext(sc);
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(DerivedTestBean.class);
	bd.setScope(scope);
	ac.registerBeanDefinition(NAME, bd);
	ac.refresh();
	return ac;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:WebApplicationContextScopeTests.java

示例10: registerPrototype

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * Register a prototype bean with the underlying bean factory.
 * <p>For more advanced needs, register with the underlying BeanFactory directly.
 * @see #getDefaultListableBeanFactory
 */
public void registerPrototype(String name, Class clazz) throws BeansException {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
	bd.setBeanClass(clazz);
	getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:12,代碼來源:StaticApplicationContext.java

示例11: registerBean

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * Register bean.
 *
 * @param beanToRegister the bean to register
 * @param beanName the bean name
 * @param scope the scope
 * @param setLazyInit the set lazy init
 * @param setAutowireCandidate the set autowire candidate
 */
public void registerBean(Class<?> beanToRegister, String beanName,
		String scope /* "session" */, boolean setLazyInit,
		boolean setAutowireCandidate) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClass(beanToRegister);
	beanDefinition.setLazyInit(setLazyInit);
	beanDefinition.setAbstract(false);
	beanDefinition.setAutowireCandidate(setAutowireCandidate);
	beanDefinition.setScope(scope);

	registry.registerBeanDefinition(beanName, beanDefinition);
}
 
開發者ID:techtrip,項目名稱:dynamicbeanloader,代碼行數:22,代碼來源:ContextAwareBeanFactory.java

示例12: registerPrototype

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
/**
 * Register a prototype bean with the underlying bean factory.
 * <p>
 * For more advanced needs, register with the underlying BeanFactory
 * directly.
 * 
 * @see #getDefaultListableBeanFactory
 */
public void registerPrototype(String name, Class clazz,
		MutablePropertyValues pvs) throws BeansException {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
	bd.setBeanClass(clazz);
	bd.setPropertyValues(pvs);
	getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
 
開發者ID:williamd1618,項目名稱:solace.common-java,代碼行數:17,代碼來源:ConfigurableApplicationContext.java

示例13: updateContext

import org.springframework.beans.factory.support.GenericBeanDefinition; //導入方法依賴的package包/類
public void updateContext(Collection<Class> classes) {
    if (beanFactory != null) {
        boolean needToRefreshRemotingContext = false;
        for (Class clazz : classes) {
            Service serviceAnnotation = (Service) clazz.getAnnotation(Service.class);
            ManagedBean managedBeanAnnotation = (ManagedBean) clazz.getAnnotation(ManagedBean.class);
            Component componentAnnotation = (Component) clazz.getAnnotation(Component.class);
            Controller controllerAnnotation = (Controller) clazz.getAnnotation(Controller.class);

            String beanName = null;
            if (serviceAnnotation != null) {
                beanName = serviceAnnotation.value();
            } else if (managedBeanAnnotation != null) {
                beanName = managedBeanAnnotation.value();
            } else if (componentAnnotation != null) {
                beanName = componentAnnotation.value();
            } else if (controllerAnnotation != null) {
                beanName = controllerAnnotation.value();
            }

            if (StringUtils.isNotBlank(beanName)) {
                GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
                beanDefinition.setBeanClass(clazz);
                Scope scope = (Scope) clazz.getAnnotation(Scope.class);
                if (scope != null) {
                    beanDefinition.setScope(scope.value());
                }

                beanFactory.registerBeanDefinition(beanName, beanDefinition);
            }

            if (StringUtils.isNotBlank(beanName)) {
                needToRefreshRemotingContext = true;
            }
        }

        if (needToRefreshRemotingContext) {
            ApplicationContext remotingContext = RemotingContextHolder.getRemotingApplicationContext();
            if (remotingContext != null && remotingContext instanceof ConfigurableApplicationContext) {
                ((ConfigurableApplicationContext) remotingContext).refresh();
            }
        }
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:45,代碼來源:SpringBeanLoader.java


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