org.springframework.beans.PropertyValue.setOptional()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(79)

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

PropertyValue.setOptional介绍

[英]Set whether this is an optional value, that is, to be ignored when no corresponding property exists on the target class.
[中]

代码示例

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

/**
 * Apply the given property value to the corresponding bean.
 */
protected void applyPropertyValue(
    ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
  BeanDefinition bd = factory.getBeanDefinition(beanName);
  BeanDefinition bdToUse = bd;
  while (bd != null) {
    bdToUse = bd;
    bd = bd.getOriginatingBeanDefinition();
  }
  PropertyValue pv = new PropertyValue(property, value);
  pv.setOptional(this.ignoreInvalidKeys);
  bdToUse.getPropertyValues().addPropertyValue(pv);
}

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

/**
 * Apply the given property value to the corresponding bean.
 */
protected void applyPropertyValue(
    ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
  BeanDefinition bd = factory.getBeanDefinition(beanName);
  BeanDefinition bdToUse = bd;
  while (bd != null) {
    bdToUse = bd;
    bd = bd.getOriginatingBeanDefinition();
  }
  PropertyValue pv = new PropertyValue(property, value);
  pv.setOptional(this.ignoreInvalidKeys);
  bdToUse.getPropertyValues().addPropertyValue(pv);
}

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

@Test
public void setUnknownOptionalProperty() {
  Simple target = new Simple("John", 2);
  AbstractPropertyAccessor accessor = createAccessor(target);
  try {
    PropertyValue value = new PropertyValue("foo", "value");
    value.setOptional(true);
    accessor.setPropertyValue(value);
  }
  catch (NotWritablePropertyException e) {
    fail("Should not have failed to set an unknown optional property.");
  }
}

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

/**
 * Apply the given property value to the corresponding bean.
 */
protected void applyPropertyValue(
    ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
  BeanDefinition bd = factory.getBeanDefinition(beanName);
  while (bd.getOriginatingBeanDefinition() != null) {
    bd = bd.getOriginatingBeanDefinition();
  }
  PropertyValue pv = new PropertyValue(property, value);
  pv.setOptional(this.ignoreInvalidKeys);
  bd.getPropertyValues().addPropertyValue(pv);
}

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

/**
 * Apply the given property value to the corresponding bean.
 */
protected void applyPropertyValue(
    ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
  BeanDefinition bd = factory.getBeanDefinition(beanName);
  while (bd.getOriginatingBeanDefinition() != null) {
    bd = bd.getOriginatingBeanDefinition();
  }
  PropertyValue pv = new PropertyValue(property, value);
  pv.setOptional(this.ignoreInvalidKeys);
  bd.getPropertyValues().addPropertyValue(pv);
}

代码示例来源:origin: stackoverflow.com

import java.beans.PropertyDescriptor;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import org.springframework.stereotype.Component;

@Component
public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

  @Override
  public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
    if (bean instanceof pak.Main) {
      for (PropertyValue pv : pvs.getPropertyValues()) {
        if ("human".equals(pv.getName())) {
          pv.setOptional(true);
        }
      }
    }
    return pvs;
  }

}

相关文章