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


Java ReflectionUtils.findField方法代码示例

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


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

示例1: JBossModulesAdapter

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public JBossModulesAdapter(ClassLoader loader) {
	this.classLoader = loader;
	try {
		Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer");
		transformer.setAccessible(true);
		this.delegatingTransformer = transformer.get(loader);
		if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
			throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " +
					this.delegatingTransformer.getClass().getName());
		}
		this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
				"addTransformer", ClassFileTransformer.class);
		this.addTransformer.setAccessible(true);
	}
	catch (Exception ex) {
		throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JBossModulesAdapter.java

示例2: parseToBean

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * 字段-值 键值对转为pojo
 *
 * @param mapping field-value mapper
 * @param clazz   待转换的pojo类-class对象
 * @throws Exception InstantiationException, IllegalAccessException
 */
public static <T> T parseToBean(Map<String, Object> mapping, Class<T> clazz) throws Exception {
    T t = clazz.newInstance();
    for (Entry<String, Object> entry : mapping.entrySet()) {

        // 字段名 下划线转为驼峰风格
        String fieldName = StringUtil.underlineToCamel(entry.getKey());

        Field field = ReflectionUtils.findField(clazz, fieldName);

        if (field != null) {
            FieldReflectUtil.setFieldValue(t, field, entry.getValue());
        }
    }
    return t;
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:23,代码来源:GeneralMapperReflectUtil.java

示例3: toString

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private String toString(DataSource dataSource) {
    if (dataSource == null) {
        return "<none>";
    } else {
        try {
            Field urlField = ReflectionUtils.findField(dataSource.getClass(), "url");
            ReflectionUtils.makeAccessible(urlField);
            return stripCredentials((String) urlField.get(dataSource));
        } catch (Exception fe) {
            try {
                Method urlMethod = ReflectionUtils.findMethod(dataSource.getClass(), "getUrl");
                ReflectionUtils.makeAccessible(urlMethod);
                return stripCredentials((String) urlMethod.invoke(dataSource, (Object[])null));
            } catch (Exception me){
                return "<unknown> " + dataSource.getClass();
            }
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Cloud-Foundry-For-Developers,代码行数:20,代码来源:HomeController.java

示例4: assertDataSourceOfType

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T extends DataSource> FlexyPoolDataSource<T> assertDataSourceOfType(DataSource dataSource, Class<T> realDataSourceClass) {
    assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
    DataSource decoratedDataSource = ((DecoratedDataSource) dataSource).getDecoratedDataSource();
    assertThat(decoratedDataSource).isInstanceOf(FlexyPoolDataSource.class);
    Field field = ReflectionUtils.findField(FlexyPoolDataSource.class, "targetDataSource");
    ReflectionUtils.makeAccessible(field);
    Object targetDataSource = ReflectionUtils.getField(field, decoratedDataSource);
    assertThat(targetDataSource).isInstanceOf(realDataSourceClass);
    return (FlexyPoolDataSource<T>) decoratedDataSource;
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:12,代码来源:FlexyPoolConfigurationTests.java

示例5: getValue

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * 获取实例属性值
 *
 * @param object    对象实例
 * @param fieldName 属性名
 * @param <T>       属性类型
 * @return 属性值
 */
static <T> T getValue(Object object, String fieldName) {
    Field field = ReflectionUtils.findField(object.getClass(), fieldName);
    Objects.requireNonNull(field, String.format("Field %s not found in %s", fieldName, object.getClass()));
    field.setAccessible(true);
    try {
        return (T) field.get(object);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(
                "Unexpected reflection exception - " + e.getClass().getName() + ": " + e.getMessage());
    }
}
 
开发者ID:laohans,项目名称:swallow-core,代码行数:20,代码来源:ReflectionUtil.java

示例6: isTransactionalApplicationEventListener

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private static boolean isTransactionalApplicationEventListener(ApplicationListener<?> listener) {

		Class<?> targetClass = AopUtils.getTargetClass(listener);

		if (!ApplicationListenerMethodAdapter.class.isAssignableFrom(targetClass)) {
			return false;
		}

		Field field = ReflectionUtils.findField(ApplicationListenerMethodAdapter.class, "method");
		ReflectionUtils.makeAccessible(field);
		Method method = (Method) ReflectionUtils.getField(field, listener);

		return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class);
	}
 
开发者ID:olivergierke,项目名称:spring-domain-events,代码行数:15,代码来源:PersistentApplicationEventMulticaster.java

示例7: getField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private static Field getField(String fieldName) {
	try {
		return ReflectionUtils.findField(WithConfigurationTestCase.class, fieldName);
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:8,代码来源:DoubleConfigurationResolverTest.java

示例8: CoapTransportResource

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public CoapTransportResource(MsgProducer msgProducer, AttributesService attributesService, DeviceAuthService authService, String name, long timeout) {
  super(name);
  this.msgProducer = msgProducer;
  this.attributesService = attributesService;
  this.authService = authService;
  this.timeout = timeout;
  // This is important to turn off existing observable logic in
  // CoapResource. We will have our own observe monitoring due to 1:1
  // observe relationship.
  this.setObservable(false);
  observerField = ReflectionUtils.findField(Exchange.class, "observer");
  observerField.setAccessible(true);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:14,代码来源:CoapTransportResource.java

示例9: should_return_the_attribute_name

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test public void
should_return_the_attribute_name(){
	
	MongoPersistentEntity<FieldWithoutAnnotation> entity = new BasicMongoPersistentEntity<FieldWithoutAnnotation>(ClassTypeInformation.from(FieldWithoutAnnotation.class));
	java.lang.reflect.Field field = ReflectionUtils.findField(FieldWithoutAnnotation.class, "name");
	
	BasicMongoPersistentProperty persistentProperty = new BasicMongoPersistentProperty(field, null, entity, new SimpleTypeHolder());		
	String fieldName = persistentProperty.getFieldName();
	
	assertEquals("Class attribute reading failed", field.getName(), fieldName);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:12,代码来源:BasicMongoPersistentPropertyTest.java

示例10: 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

示例11: getRowIndex

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Integer getRowIndex(Result<?> result) {
    Field rowIndexField = ReflectionUtils.findField(result.getClass(), "rowIndex");
    rowIndexField.setAccessible(true);
    return (Integer) ReflectionUtils.getField(rowIndexField, result);
}
 
开发者ID:mhewedy,项目名称:spwrap,代码行数:6,代码来源:SpringResultSetAutoMapper.java

示例12: 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

示例13: 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

示例14: setField

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * 设置对应参数的值
 * 
 * @param target
 * @param methodName
 * @param args
 * @return
 * @throws Exception
 */
public static void setField(Object target, String fieldName, Object args) throws Exception {
    // 查找对应的方法
    Field field = ReflectionUtils.findField(target.getClass(), fieldName);
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, target, args);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:16,代码来源:TestUtils.java

示例15: setValue

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * 给实例属性赋值
 *
 * @param object    对象实例
 * @param fieldName 属性名
 * @param value     属性值
 */
static void setValue(Object object, String fieldName, Object value) {
    Field field = ReflectionUtils.findField(object.getClass(), fieldName);
    Objects.requireNonNull(field, String.format("Field %s not found in %s", fieldName, object.getClass()));
    setValue(object, field, value);
}
 
开发者ID:laohans,项目名称:swallow-core,代码行数:13,代码来源:ReflectionUtil.java


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