本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}