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


Java ReflectionUtils.setField方法代码示例

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


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

示例1: VertxImplEx

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public VertxImplEx(String name, VertxOptions vertxOptions) {
  super(vertxOptions);

  if (StringUtils.isEmpty(name)) {
    return;
  }

  Field field = ReflectionUtils.findField(VertxImpl.class, "eventLoopThreadFactory");
  field.setAccessible(true);
  VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, this);

  field = ReflectionUtils.findField(eventLoopThreadFactory.getClass(), "prefix");
  field.setAccessible(true);

  String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
  ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:VertxImplEx.java

示例2: encode

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@PrePersist
@PreUpdate
public void encode(Object target) {
	AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
	if (metadata.isCheckable()) {
		StringBuilder sb = new StringBuilder();
		for (Field field : metadata.getCheckedFields()) {
			ReflectionUtils.makeAccessible(field);
			Object value = ReflectionUtils.getField(field, target);
			if (value instanceof Date) {
				throw new RuntimeException("不支持时间类型字段加密!");
			}
			sb.append(value).append(" - ");
		}
		sb.append(MD5_KEY);
		LOGGER.debug("加密数据:" + sb);
		String hex = MD5Utils.encode(sb.toString());
		Field checksumField = metadata.getCheckableField();
		ReflectionUtils.makeAccessible(checksumField);
		ReflectionUtils.setField(checksumField, target, hex);
	}
}
 
开发者ID:onsoul,项目名称:os,代码行数:23,代码来源:CheckingEntityListener.java

示例3: after

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override protected void after()
{
    // For all objects that have been tampered with, we'll revert them to their original state.
    for (int i = pristineFieldValues.size() - 1; i >= 0; i-- )
    {
        FieldValueOverride override = pristineFieldValues.get(i);
        
        if (log.isDebugEnabled())
        {
            log.debug("Reverting mocked field '" + override.fieldName + "' on object " + override.objectContainingField + " to original value '" + override.fieldPristineValue + "'");
        }
        
        // Hack into the Java field object
        Field f = ReflectionUtils.findField(override.objectContainingField.getClass(), override.fieldName);
        ReflectionUtils.makeAccessible(f);
        // and revert its value.
        ReflectionUtils.setField(f, override.objectContainingField, override.fieldPristineValue);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:20,代码来源:TemporaryMockOverride.java

示例4: main

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public static void main(String[] args) {
    Customer target = new Customer();
    target.setId("1");

    Customer des = new Customer();
    Field[] fields = Customer.class.getDeclaredFields();
    // ReflectionUtils.getAllDeclaredMethods(leafClass)
    for (Field field : fields) {
        ReflectionUtils.makeAccessible(field);
        Object v = ReflectionUtils.getField(field, target);
        System.err.println(field.getName() + "++ " + v);
        ReflectionUtils.setField(field, des, v);
    }
    System.err.println(des.getId());
    // ReflectionUtils.getAllDeclaredMethods(entityClass);

}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:18,代码来源:BaseRepositoryImpl.java

示例5: processFields

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void processFields(Object bean, Field[] declaredFields) {
  for (Field field : declaredFields) {
    ApolloConfig annotation = AnnotationUtils.getAnnotation(field, ApolloConfig.class);
    if (annotation == null) {
      continue;
    }

    Preconditions.checkArgument(Config.class.isAssignableFrom(field.getType()),
        "Invalid type: %s for field: %s, should be Config", field.getType(), field);

    String namespace = annotation.value();
    Config config = ConfigService.getConfig(namespace);

    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, bean, config);
  }
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ApolloAnnotationProcessor.java

示例6: setId

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private static void setId(Class<?> clazz, Object instance, String fieldName, Object value) {
	try {
		Field field = ReflectionUtils.findField(clazz, fieldName);
		field.setAccessible(true);
		int modifiers = field.getModifiers();
		Field modifierField = field.getClass().getDeclaredField("modifiers");
		modifiers = modifiers & ~Modifier.FINAL;
		modifierField.setAccessible(true);
		modifierField.setInt(field, modifiers);
		ReflectionUtils.setField(field, instance, value);
	} catch (ReflectiveOperationException e) {
		throw new IllegalArgumentException(e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:15,代码来源:StateMachineTests.java

示例7: handleReferenceField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void handleReferenceField(Object obj, Field field,
    RpcReference reference) {
  String microserviceName = reference.microserviceName();
  microserviceName = resolver.resolveStringValue(microserviceName);

  PojoReferenceMeta pojoReference = new PojoReferenceMeta();
  pojoReference.setMicroserviceName(microserviceName);
  pojoReference.setSchemaId(reference.schemaId());
  pojoReference.setConsumerIntf(field.getType());

  pojoReference.afterPropertiesSet();

  ReflectionUtils.makeAccessible(field);
  ReflectionUtils.setField(field, obj, pojoReference.getProxy());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:16,代码来源:RpcReferenceProcessor.java

示例8: resetConfig

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public static void resetConfig() {
  ReflectionUtils.setField(FIELD_INSTANCE, null, null);
  ReflectionUtils.setField(FIELD_CUSTOM_CONFIGURATION_INSTALLED, null, false);
  ReflectionUtils.setField(FIELD_CONFIG, null, null);
  ReflectionUtils.setField(FIELD_INITIALIZED_WITH_DEFAULT_CONFIG, null, false);
  ReflectionUtils.setField(FIELD_DYNAMIC_PROPERTY_SUPPORTIMPL, null, null);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:ArchaiusUtils.java

示例9: replaceSql

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void replaceSql(String pageSql, PreparedStatementCreator psc) {
    Field sqlField = null;
    sqlField = ReflectionUtils.findField(psc.getClass(), "actualSql");
    if (sqlField == null) {
        sqlField = ReflectionUtils.findField(String.class, "sql");
        if (sqlField == null) {
            return;
        }
    }
    sqlField.setAccessible(true);
    ReflectionUtils.setField(sqlField, psc, pageSql);
}
 
开发者ID:ChenAt,项目名称:common-dao,代码行数:13,代码来源:QueryInterceptor.java

示例10: setTemporaryField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public void setTemporaryField(Object objectContainingField, String fieldName, Object fieldValue)
{
    if (log.isDebugEnabled())
    {
        log.debug("Overriding field '" + fieldName + "' on object " + objectContainingField + " to new value '" + fieldValue + "'");
    }
    
    // Extract the pristine value of the field we're going to mock.
    Field f = ReflectionUtils.findField(objectContainingField.getClass(), fieldName);
    
    if (f == null)
    {
        final String msg = "Object of type '" + objectContainingField.getClass().getSimpleName() + "' has no field named '" + fieldName + "'";
        if (log.isDebugEnabled())
        {
            log.debug(msg);
        }
        throw new IllegalArgumentException(msg);
    }
    
    ReflectionUtils.makeAccessible(f);
    Object pristineValue = ReflectionUtils.getField(f, objectContainingField);
    
    // and add it to the list.
    pristineFieldValues.add(new FieldValueOverride(objectContainingField, fieldName, pristineValue));
    
    // and set it on the object
    ReflectionUtils.setField(f, objectContainingField, fieldValue);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:TemporaryMockOverride.java

示例11: testDefaultJarSettings

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public void testDefaultJarSettings() throws Exception {

		Properties defaultSettings = bundleCreator.getSettings();
		Field field = ReflectionUtils.findField(AbstractConfigurableBundleCreatorTests.class, "jarSettings" , Properties.class);
		ReflectionUtils.makeAccessible(field);
		ReflectionUtils.setField(field, null, defaultSettings);
		assertNotNull(defaultSettings);
		assertNotNull(bundleCreator.getRootPath());
		assertNotNull(bundleCreator.getBundleContentPattern());
		assertNotNull(bundleCreator.getManifestLocation());
	}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:ConfigurableBundleCreatorTestsTest.java

示例12: setLastTimeRun

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public void setLastTimeRun(LocalDateTime lastTimeRun) {
    Field lastTimeRunField = ReflectionUtils.findField(AbstractNotifier.class, "lastTimeRun");
    ReflectionUtils.makeAccessible(lastTimeRunField);
    ReflectionUtils.setField(lastTimeRunField, this, lastTimeRun);
}
 
开发者ID:gilles-stragier,项目名称:quickmon,代码行数:6,代码来源:AbstractNotifierTest.java

示例13: setCreatedOn

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public void setCreatedOn(LocalDateTime lastTimeRun) {
    Field createdOnField = ReflectionUtils.findField(AbstractNotifier.class, "createdOn");
    ReflectionUtils.makeAccessible(createdOnField);
    ReflectionUtils.setField(createdOnField, this, lastTimeRun);
}
 
开发者ID:gilles-stragier,项目名称:quickmon,代码行数:6,代码来源:AbstractNotifierTest.java

示例14: setField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
void setField(String name, Object value) {
	Field field = ReflectionUtils.findField(EurekaJacksonCodec.class, name);
	ReflectionUtils.makeAccessible(field);
	ReflectionUtils.setField(field, this, value);
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:6,代码来源:CloudJacksonJson.java

示例15: setField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public static <T> void setField(final T targetObject, final String fieldName, final Object targetValue) {
    final Field field = ReflectionUtils.findField(targetObject.getClass(), fieldName);
    field.setAccessible(true);
    ReflectionUtils.setField(field, targetObject, targetValue);
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:6,代码来源:ReflectionHelper.java


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