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


Java ReflectionUtils.getField方法代码示例

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


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

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

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

示例3: checking

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@PostLoad
public void checking(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);
		String checksum = (String) ReflectionUtils.getField(checksumField, target);
		if (!checksum.equals(hex)) {
			//throw new RuntimeException("数据验证失败!");
		}
	}
}
 
开发者ID:onsoul,项目名称:os,代码行数:25,代码来源:CheckingEntityListener.java

示例4: read

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object read(Class<? extends Object> clazz,
    HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
  MessageBodyClientHttpResponseWrapper respWrapper = (MessageBodyClientHttpResponseWrapper) inputMessage;
  CseClientHttpResponse resp =
      (CseClientHttpResponse) ReflectionUtils.getField(RESPONSE_FIELD, respWrapper);
  return resp.getResult();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:CseHttpMessageConverter.java

示例5: RuntimeMapFieldProtobuf

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public RuntimeMapFieldProtobuf(RuntimeMapField<T, Object, Object> runtimeMapField,
    java.lang.reflect.Field field) {
  super(runtimeMapField.type, runtimeMapField.number, runtimeMapField.name, null,
      runtimeMapField.schema.messageFactory);

  entrySchema = (Schema<Entry<Object, Object>>) ReflectionUtils.getField(entrySchemaField,
      runtimeMapField.schema);

  this.runtimeMapField = runtimeMapField;
  this.field = field;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:RuntimeMapFieldProtobuf.java

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

示例7: findStrategy

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T extends ConnectionAcquiringStrategy> T findStrategy(FlexyPoolDataSource<?> flexyPoolDataSource,
        Class<T> factoryClass) {
    Field field = ReflectionUtils.findField(FlexyPoolDataSource.class, "connectionAcquiringStrategies");
    ReflectionUtils.makeAccessible(field);
    Set<ConnectionAcquiringStrategy> strategies =
            (Set<ConnectionAcquiringStrategy>) ReflectionUtils.getField(field, flexyPoolDataSource);
    return (T) strategies.stream().filter(factoryClass::isInstance).findFirst().orElse(null);
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:10,代码来源:FlexyPoolConfigurationTests.java

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

示例9: configMutliCluster

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public void configMutliCluster(ZooKeeper zk) {
    if (_servers.size() == 1) {
        return;
    }
    String cluster1 = _servers.get(0);
    try {
        if (_servers.size() > 1) {
            // 强制的声明accessible
            ReflectionUtils.makeAccessible(clientCnxnField);
            ReflectionUtils.makeAccessible(hostProviderField);
            ReflectionUtils.makeAccessible(serverAddressesField);

            // 添加第二组集群列表
            for (int i = 1; i < _servers.size(); i++) {
                String cluster = _servers.get(i);
                // 强制获取zk中的地址信息
                ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
                HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
                List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField,
                                                                                                         hostProvider);
                // 添加第二组集群列表
                serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
            }
        }
    } catch (Exception e) {
        try {
            if (zk != null) {
                zk.close();
            }
        } catch (InterruptedException ie) {
            // ignore interrupt
        }
        throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
    }

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:37,代码来源:ZooKeeperx.java

示例10: removeInjectCache

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void removeInjectCache(Object controller) {
    AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor =
            ctx.getBean(AutowiredAnnotationBeanPostProcessor.class);
    Map<String, InjectionMetadata> injectionMetadataMap =
            (Map<String, InjectionMetadata>) ReflectionUtils.getField(injectionMetadataCacheField, autowiredAnnotationBeanPostProcessor);
    injectionMetadataMap.remove(controller.getClass().getName());
}
 
开发者ID:cattientk,项目名称:daros-dynamic,代码行数:8,代码来源:DynamicRegisterGroovyFile.java

示例11: configure

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
void configure(AuthenticationManagerBuilder auth) throws Exception {
    CasAuthenticationProvider provider = providerBuilder.build();
    provider.setServiceProperties(serviceProperties);
    Field field = ReflectionUtils.findField(CasAuthenticationProvider.class, "ticketValidator");
    ReflectionUtils.makeAccessible(field);
    if (ReflectionUtils.getField(field, provider) == null) {
        provider.setTicketValidator(ticketValidator);
    }
    provider.afterPropertiesSet();
    auth.authenticationProvider(provider);
}
 
开发者ID:kakawait,项目名称:cas-security-spring-boot-starter,代码行数:12,代码来源:CasHttpSecurityConfigurer.java

示例12: getBeanFactory

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private ConfigurableBeanFactory getBeanFactory(Object enhancedConfigInstance) {
	Field field = ReflectionUtils.findField(enhancedConfigInstance.getClass(), BEAN_FACTORY_FIELD);
	Assert.state(field != null, "Unable to find generated bean factory field");
	Object beanFactory = ReflectionUtils.getField(field, enhancedConfigInstance);
	Assert.state(beanFactory != null, "BeanFactory has not been injected into @Configuration class");
	Assert.state(beanFactory instanceof ConfigurableBeanFactory,
			"Injected BeanFactory is not a ConfigurableBeanFactory");
	return (ConfigurableBeanFactory) beanFactory;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ConfigurationClassEnhancer.java

示例13: isCrossApp

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
protected boolean isCrossApp(String uriTemplate, UriComponentsBuilder builder) {
  String host = (String) ReflectionUtils.getField(hostField, builder);
  int pos = RestConst.URI_PREFIX.length() + host.length();
  return uriTemplate.charAt(pos) == ':';
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:6,代码来源:CseUriTemplateHandler.java

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

示例15: getId

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public ID getId(T entity) {
    return (ID) ReflectionUtils.getField(id, entity);
}
 
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:4,代码来源:DocumentDbEntityInformation.java


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