当前位置: 首页>>代码示例>>Java>>正文


Java RootBeanDefinition.setLazyInit方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.RootBeanDefinition.setLazyInit方法的典型用法代码示例。如果您正苦于以下问题:Java RootBeanDefinition.setLazyInit方法的具体用法?Java RootBeanDefinition.setLazyInit怎么用?Java RootBeanDefinition.setLazyInit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.RootBeanDefinition的用法示例。


在下文中一共展示了RootBeanDefinition.setLazyInit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(beanClass);
    beanDefinition.setLazyInit(false);

    String key = element.getAttribute("key");
    String value = element.getAttribute("value");
    String hide = element.getAttribute("hide");
    if(CommonUtils.isTrue(hide)){
        JSFContext.putGlobalVal(Constants.HIDE_KEY_PREFIX + key, value);
    } else {
        JSFContext.putGlobalVal(key, value);
    }

    beanDefinition.getPropertyValues().addPropertyValue("key", key);
    beanDefinition.getPropertyValues().addPropertyValue("value", value);
    beanDefinition.getPropertyValues().addPropertyValue("hide", Boolean.valueOf(hide));

    return beanDefinition;
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:22,代码来源:JSFParameterDefinitionParser.java

示例2: fixName

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
/**
 * ID处理
 * 如果标签上没有定义name 则自动生成name
 * @param element
 * @param parserContext
 */
private Pair<RootBeanDefinition, String/*name*/> fixName(Element element, ParserContext parserContext, Class beanClass){
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(beanClass);
    beanDefinition.setLazyInit(false);

    String name = element.getAttribute("name");

    synchronized (BaymaxBeanDefinitionParser.class){
        if (name == null || name.length() == 0) {
            name = "Baymax-" + beanClass.getSimpleName();
            while (parserContext.getRegistry().containsBeanDefinition(name)) {
                name += (counter++);
            }
        }
        if (name != null && name.length() > 0) {
            if (parserContext.getRegistry().containsBeanDefinition(name)) {
                throw new IllegalStateException("Duplicate spring bean id " + name);
            }
            parserContext.getRegistry().registerBeanDefinition(name, beanDefinition);
        }
    }
    return new Pair<RootBeanDefinition, String>(beanDefinition, name);
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:30,代码来源:BaymaxBeanDefinitionParser.java

示例3: doTestLazyResourceInjection

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
private void doTestLazyResourceInjection(Class<? extends TestBeanHolder> annotatedBeanClass) {
	AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
	RootBeanDefinition abd = new RootBeanDefinition(annotatedBeanClass);
	abd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ac.registerBeanDefinition("annotatedBean", abd);
	RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
	tbd.setLazyInit(true);
	ac.registerBeanDefinition("testBean", tbd);
	ac.refresh();

	TestBeanHolder bean = ac.getBean("annotatedBean", TestBeanHolder.class);
	assertFalse(ac.getBeanFactory().containsSingleton("testBean"));
	assertNotNull(bean.getTestBean());
	assertNull(bean.getTestBean().getName());
	assertTrue(ac.getBeanFactory().containsSingleton("testBean"));
	TestBean tb = (TestBean) ac.getBean("testBean");
	tb.setName("tb");
	assertSame("tb", bean.getTestBean().getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:LazyAutowiredAnnotationBeanPostProcessorTests.java

示例4: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
public BeanDefinition parse(Element element, ParserContext parserContext) {
  String id = element.getAttribute("id");
  if (StringUtils.isEmpty(id)) {
    String name = element.getAttribute("name");
    if (!StringUtils.isEmpty(name)) {
      id = name;
    } else {
      id = RpcAnnotation.class.getName();
    }
  }
  if (parserContext.getRegistry().containsBeanDefinition(id)) {
    throw new IllegalStateException("Duplicate spring bean id " + id);
  }
  String annotationPackage = element.getAttribute("package");
  RootBeanDefinition beanDefinition = new RootBeanDefinition();
  beanDefinition.setBeanClass(RpcAnnotation.class);
  beanDefinition.setLazyInit(false);
  if (!StringUtils.isEmpty(annotationPackage)) {
    beanDefinition.getPropertyValues().addPropertyValue("annotationPackage", annotationPackage);
  }
  parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
  return beanDefinition;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:24,代码来源:RpcAnnotationParser.java

示例5: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {

  String interfacename = element.getAttribute("interfacename");
  String id = element.getAttribute("id");
  String preferredZone = element.getAttribute("preferredZone");
  boolean usedTls = Boolean.valueOf(element.getAttribute("usedTls"));
  int timeout = Strings.isNullOrEmpty(element.getAttribute("timeout")) ? 0
      : Integer.parseInt(element.getAttribute("timeout"));
  RootBeanDefinition beanDefinition = new RootBeanDefinition();
  beanDefinition.setBeanClass(RpcReference.class);
  beanDefinition.setLazyInit(false);

  beanDefinition.getPropertyValues().addPropertyValue("interfacename", interfacename);
  beanDefinition.getPropertyValues().addPropertyValue("beanName", id);
  beanDefinition.getPropertyValues().addPropertyValue("preferredZone", preferredZone);
  beanDefinition.getPropertyValues().addPropertyValue("usedTls", usedTls);
  beanDefinition.getPropertyValues().addPropertyValue("timeout", timeout);
  
  parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
  return beanDefinition;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:23,代码来源:RpcReferenceParser.java

示例6: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    FieldDefine fieldDefine = parseFieldDefine(element);
    String id = fieldDefine.getId();
    if (StringUtils.isEmpty(id)) {
        id = fieldDefine.toString()+"-"+System.currentTimeMillis();
    }
    
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(FieldDefine.class);
    beanDefinition.setLazyInit(false);

    BeanDefinitionRegistry registry = parserContext.getRegistry();
    if (registry.containsBeanDefinition(id)) {
        throw new IllegalStateException("Duplicate spring bean id " + id);
    }
    registry.registerBeanDefinition(id, beanDefinition);

    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
    propertyValues.addPropertyValue("id", id);
    propertyValues.addPropertyValue("name", fieldDefine.getName());
    propertyValues.addPropertyValue("type", fieldDefine.getType());
    propertyValues.addPropertyValue("selector", fieldDefine.getSelector());
    propertyValues.addPropertyValue("processor", fieldDefine.getProcessor());
    propertyValues.addPropertyValue("defines", fieldDefine.getDefines());

    return beanDefinition;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:29,代码来源:FieldDefineBeanDefinitionParser.java

示例7: testCustomWithAsm

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomWithAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("customConfig", new RootBeanDefinition(CustomConfig.class.getName()));
	RootBeanDefinition customPojo = new RootBeanDefinition(CustomPojo.class.getName());
	customPojo.setLazyInit(true);
	ctx.registerBeanDefinition("customPojo", customPojo);
	ctx.refresh();
	assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
	CustomPojo pojo = ctx.getBean(CustomPojo.class);
	assertThat(pojo.testBean.getName(), equalTo("interesting"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:BeanMethodQualificationTests.java

示例8: singleSmartLifecycleAutoStartupWithLazyInit

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void singleSmartLifecycleAutoStartupWithLazyInit() throws Exception {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition bd = new RootBeanDefinition(DummySmartLifecycleBean.class);
	bd.setLazyInit(true);
	context.registerBeanDefinition("bean", bd);
	context.refresh();
	DummySmartLifecycleBean bean = context.getBean("bean", DummySmartLifecycleBean.class);
	assertTrue(bean.isRunning());
	context.stop();
	assertFalse(bean.isRunning());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:DefaultLifecycleProcessorTests.java

示例9: singleSmartLifecycleAutoStartupWithLazyInitFactoryBean

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void singleSmartLifecycleAutoStartupWithLazyInitFactoryBean() throws Exception {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition bd = new RootBeanDefinition(DummySmartLifecycleFactoryBean.class);
	bd.setLazyInit(true);
	context.registerBeanDefinition("bean", bd);
	context.refresh();
	DummySmartLifecycleFactoryBean bean = context.getBean("&bean", DummySmartLifecycleFactoryBean.class);
	assertTrue(bean.isRunning());
	context.stop();
	assertFalse(bean.isRunning());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:DefaultLifecycleProcessorTests.java

示例10: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {

  String id = element.getAttribute("id");
  String interfaceName = element.getAttribute("interface");
  String className = element.getAttribute("class");
  String ref = element.getAttribute("ref");
  
  if (Strings.isNullOrEmpty(id)) {
    String generatedBeanName = element.getAttribute("name");
    if (Strings.isNullOrEmpty(generatedBeanName)) {
      generatedBeanName = element.getAttribute("interface");
    }
    id = generatedBeanName;
  }
  if (!Strings.isNullOrEmpty(id)) {
    if (parserContext.getRegistry().containsBeanDefinition(id)) {
      throw new IllegalStateException("Duplicate spring bean id " + id);
    }
  }
  
  RootBeanDefinition beanDefinition = new RootBeanDefinition();
  beanDefinition.setBeanClass(RpcService.class);
  beanDefinition.setLazyInit(false);
  
  beanDefinition.getPropertyValues().addPropertyValue("id", id);
  beanDefinition.getPropertyValues().addPropertyValue("interfaceName", interfaceName);
  beanDefinition.getPropertyValues().addPropertyValue("implementationClass", className);
  beanDefinition.getPropertyValues().addPropertyValue("ref", ref);

  parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
  return beanDefinition;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:34,代码来源:RpcServiceParser.java

示例11: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(beanClass);
    beanDefinition.setLazyInit(false);
    if (!parserContext.getRegistry().containsBeanDefinition("txazo-config")) {
        parserContext.getRegistry().registerBeanDefinition("txazo-config", beanDefinition);
    }
    return beanDefinition;
}
 
开发者ID:txazo,项目名称:spring,代码行数:11,代码来源:TxazoBeanDefinitionParser.java

示例12: listenersInApplicationContext

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void listenersInApplicationContext() {
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class));
	RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class);
	listener2.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("listener1"));
	listener2.setLazyInit(true);
	context.registerBeanDefinition("listener2", listener2);
	context.refresh();
	assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));

	MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
	MyOtherEvent event1 = new MyOtherEvent(context);
	context.publishEvent(event1);
	assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
	MyEvent event2 = new MyEvent(context);
	context.publishEvent(event2);
	assertTrue(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
	MyEvent event3 = new MyEvent(context);
	context.publishEvent(event3);
	MyOtherEvent event4 = new MyOtherEvent(context);
	context.publishEvent(event4);
	assertTrue(listener1.seenEvents.contains(event1));
	assertTrue(listener1.seenEvents.contains(event2));
	assertTrue(listener1.seenEvents.contains(event3));
	assertTrue(listener1.seenEvents.contains(event4));

	listener1.seenEvents.clear();
	context.publishEvent(event1);
	context.publishEvent(event2);
	context.publishEvent(event3);
	context.publishEvent(event4);
	assertTrue(listener1.seenEvents.contains(event1));
	assertTrue(listener1.seenEvents.contains(event2));
	assertTrue(listener1.seenEvents.contains(event3));
	assertTrue(listener1.seenEvents.contains(event4));

	AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
	assertEquals(2, multicaster.retrieverCache.size());

	context.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:ApplicationContextEventTests.java

示例13: inject

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
    Field field = (Field) this.member;
    //find consumer field
    //auto initialize dubbo Remote Caller
    DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(ConsumerBean.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.setBeanClassName(ConsumerBean.class.getName());

    ConstructorArgumentValues values = new ConstructorArgumentValues();
    values.addIndexedArgumentValue(0, field.getType().getName());

    beanDefinition.setConstructorArgumentValues(values);


    factory.registerBeanDefinition(field.getName(), beanDefinition);

    try {
        Object value;
        if (this.cached) {
            value = resolvedCachedArgument(beanName, this.cachedFieldValue);
        }
        else {
            DependencyDescriptor descriptor = new DependencyDescriptor(field, this.required);
            Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
            TypeConverter typeConverter = beanFactory.getTypeConverter();
            value = beanFactory.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
            synchronized (this) {
                if (!this.cached) {
                    if (value != null || this.required) {
                        this.cachedFieldValue = descriptor;
                        registerDependentBeans(beanName, autowiredBeanNames);
                        if (autowiredBeanNames.size() == 1) {
                            String autowiredBeanName = autowiredBeanNames.iterator().next();
                            if (beanFactory.containsBean(autowiredBeanName)) {
                                if (beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
                                    this.cachedFieldValue = new RuntimeBeanReference(autowiredBeanName);
                                }
                            }
                        }
                    }
                    else {
                        this.cachedFieldValue = null;
                    }
                    this.cached = true;
                }
            }
        }
        if (value != null) {
            ReflectionUtils.makeAccessible(field);
            field.set(bean, value);
        }
    }
    catch (Throwable ex) {
        throw new BeanCreationException("Could not autowire field: " + field, ex);
    }
}
 
开发者ID:xyp260466,项目名称:dubbo-lite,代码行数:60,代码来源:DubboConsumerAnnotationBeanPostProcessor.java


注:本文中的org.springframework.beans.factory.support.RootBeanDefinition.setLazyInit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。