org.springframework.beans.factory.BeanFactory.isPrototype()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(71)

本文整理了Java中org.springframework.beans.factory.BeanFactory.isPrototype()方法的一些代码示例,展示了BeanFactory.isPrototype()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanFactory.isPrototype()方法的具体详情如下:
包路径:org.springframework.beans.factory.BeanFactory
类名称:BeanFactory
方法名:isPrototype

BeanFactory.isPrototype介绍

[英]Is this bean a prototype? That is, will #getBean always return independent instances?

Note: This method returning false does not clearly indicate a singleton object. It indicates non-independent instances, which may correspond to a scoped bean as well. Use the #isSingleton operation to explicitly check for a shared singleton instance.

Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
[中]这个bean是原型吗?也就是说,getBean是否总是返回独立实例?
注意:此方法返回false并不能清楚地指示singleton对象。它表示非独立实例,也可能对应于作用域bean。使用#isSingleton操作显式检查共享的singleton实例。
将别名转换回相应的规范bean名称。将询问父工厂是否在此工厂实例中找不到该bean。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a PrototypeAspectInstanceFactory. AspectJ will be called to
 * introspect to create AJType metadata using the type returned for the
 * given bean name from the BeanFactory.
 * @param beanFactory the BeanFactory to obtain instance(s) from
 * @param name the name of the bean
 */
public PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name) {
  super(beanFactory, name);
  if (!beanFactory.isPrototype(name)) {
    throw new IllegalArgumentException(
        "Cannot use PrototypeAspectInstanceFactory with bean named '" + name + "': not a prototype");
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
  super.setBeanFactory(beanFactory);
  // Check whether the target bean is defined as prototype.
  if (!beanFactory.isPrototype(getTargetBeanName())) {
    throw new BeanDefinitionStoreException(
        "Cannot use prototype-based TargetSource against non-prototype bean with name '" +
        getTargetBeanName() + "': instances would not be independent");
  }
}

代码示例来源:origin: spring-projects/spring-framework

if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
  return parentBeanFactory.isPrototype(originalBeanName(name));

代码示例来源:origin: org.springframework/spring-beans

if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
  return parentBeanFactory.isPrototype(originalBeanName(name));

代码示例来源:origin: spring-projects/spring-integration

@Override
protected void onInit() {
  if (StringUtils.hasText(this.targetBeanName)) {
    Assert.isTrue(this.getBeanFactory().isPrototype(this.targetBeanName),
        "target bean [" + this.targetBeanName + "] must have 'prototype' scope");
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public boolean isPrototype() {
  if (this.beanFactory == null) {
    throw new FactoryBeanNotInitializedException();
  }
  return this.beanFactory.isPrototype(this.targetBeanName);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws

private void createAndPublishEndpoint(String url, Object implementor) {
  ServerFactoryBean serverFactory = null;
  if (prototypeServerFactoryBeanName != null) {
    if (!beanFactory.isPrototype(prototypeServerFactoryBeanName)) {
      throw
        new IllegalArgumentException(
    if (!beanFactory.isPrototype(prototypeDataBindingBeanName)) {
      throw
        new IllegalArgumentException(

代码示例来源:origin: camunda/camunda-bpm-platform

if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
  return parentBeanFactory.isPrototype(originalBeanName(name));

代码示例来源:origin: org.kuali.rice/rice-it-internal-tools

@Override
public boolean isPrototype(String name) throws NoSuchBeanDefinitionException {
  for (BeanFactory f : factories) {
    try {
      boolean b = f.isPrototype(name);
      if (b) {
        return b;
      }    
    } catch (BeansException e) {
      LOG.info("bean exception", e);
    }
  }
  return false;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Create a PrototypeAspectInstanceFactory. AspectJ will be called to
 * introspect to create AJType metadata using the type returned for the
 * given bean name from the BeanFactory.
 * @param beanFactory the BeanFactory to obtain instance(s) from
 * @param name the name of the bean
 */
public PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name) {
  super(beanFactory, name);
  if (!beanFactory.isPrototype(name)) {
    throw new IllegalArgumentException(
        "Cannot use PrototypeAspectInstanceFactory with bean named '" + name + "': not a prototype");
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-aop

/**
 * Create a PrototypeAspectInstanceFactory. AspectJ will be called to
 * introspect to create AJType metadata using the type returned for the
 * given bean name from the BeanFactory.
 * @param beanFactory the BeanFactory to obtain instance(s) from
 * @param name the name of the bean
 */
public PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name) {
  super(beanFactory, name);
  if (!beanFactory.isPrototype(name)) {
    throw new IllegalArgumentException(
        "Cannot use PrototypeAspectInstanceFactory with bean named '" + name + "': not a prototype");
  }
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@Override
protected void onInit() {
  if (StringUtils.hasText(this.targetBeanName)) {
    Assert.isTrue(this.getBeanFactory().isPrototype(this.targetBeanName),
        "target bean [" + this.targetBeanName + "] must have 'prototype' scope");
  }
}

代码示例来源:origin: uk.org.ponder.rsf/rsf-core-servletutil

public boolean isPrototype() {
  if (this.beanFactory == null) {
    throw new FactoryBeanNotInitializedException();
  }
  return this.beanFactory.isPrototype(this.targetBeanName);
}

代码示例来源:origin: org.eclipse.gemini.blueprint/gemini-blueprint-core

@Override
public boolean isPrototype() {
  if (this.beanFactory == null) {
    throw new FactoryBeanNotInitializedException();
  }
  return this.beanFactory.isPrototype(this.targetBeanName);
}

代码示例来源:origin: com.haulmont.addon.dashboard/dashboard-web

public Component generateAssistanceBeanNameField(Datasource<Dashboard> datasource, String fieldId) {
  Map<String, DashboardViewAssistant> assistantBeanMap = AppBeans.getAll(DashboardViewAssistant.class);
  BeanFactory bf = ((AbstractApplicationContext) AppContext.getApplicationContext()).getBeanFactory();
  List<String> prototypeBeanNames = assistantBeanMap.keySet().stream()
      .filter(bn -> bf.isPrototype(bn))
      .collect(toList());
  LookupField lookupField = componentsFactory.createComponent(LookupField.class);
  lookupField.setOptionsList(prototypeBeanNames);
  return lookupField;
}

代码示例来源:origin: com.haulmont.addon.dashboard/dashboard-web

private void initAssistant(WebDashboardFrame frame) {
  String assistantBeanName = StringUtils.isEmpty(getAssistantBeanName()) ? dashboard.getAssistantBeanName() : getAssistantBeanName();
  if (StringUtils.isNotEmpty(assistantBeanName)) {
    DashboardViewAssistant assistantBean = AppBeans.get(assistantBeanName, DashboardViewAssistant.class);
    BeanFactory bf = ((AbstractApplicationContext) AppContext.getApplicationContext()).getBeanFactory();
    if (assistantBean != null && bf.isPrototype(assistantBeanName)) {
      assistantBean.init(frame);
      dashboardViewAssistant = assistantBean;
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-aop

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
  super.setBeanFactory(beanFactory);
  // Check whether the target bean is defined as prototype.
  if (!beanFactory.isPrototype(getTargetBeanName())) {
    throw new BeanDefinitionStoreException(
        "Cannot use prototype-based TargetSource against non-prototype bean with name '" +
        getTargetBeanName() + "': instances would not be independent");
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
  super.setBeanFactory(beanFactory);
  // Check whether the target bean is defined as prototype.
  if (!beanFactory.isPrototype(getTargetBeanName())) {
    throw new BeanDefinitionStoreException(
        "Cannot use prototype-based TargetSource against non-prototype bean with name '" +
        getTargetBeanName() + "': instances would not be independent");
  }
}

代码示例来源:origin: apache/cxf

private void createAndPublishEndpoint(String url, Object implementor) {
  ServerFactoryBean serverFactory = null;
  if (prototypeServerFactoryBeanName != null) {
    if (!beanFactory.isPrototype(prototypeServerFactoryBeanName)) {
      throw
        new IllegalArgumentException(
    if (!beanFactory.isPrototype(prototypeDataBindingBeanName)) {
      throw
        new IllegalArgumentException(

代码示例来源:origin: apache/servicemix-bundles

if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
  return parentBeanFactory.isPrototype(originalBeanName(name));
if (mbd.isPrototype()) {

相关文章