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


Java AnnotatedElementUtils.findMergedAnnotation方法代码示例

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


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

示例1: doWith

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {

	if (methodFound) {
		return;
	}

	TransactionalEventListener listener = AnnotatedElementUtils.findMergedAnnotation(method,
			TransactionalEventListener.class);

	if (listener == null) {
		return;
	}

	this.methodFound = true;

	bean = createCompletionRegisteringProxy(bean);
}
 
开发者ID:olivergierke,项目名称:spring-domain-events,代码行数:19,代码来源:CompletionRegisteringBeanPostProcessor.java

示例2: customizeContext

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?> testClass = mergedConfig.getTestClass();
    FlywayTest flywayAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, FlywayTest.class);

    BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
    RootBeanDefinition registrarDefinition = new RootBeanDefinition();

    registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(0, databaseAnnotation);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(1, flywayAnnotation);

    registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:17,代码来源:EmbeddedPostgresContextCustomizerFactory.java

示例3: init

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public void init(Method listenMethod) {
    TheFlowListener theFlowListenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod.getDeclaringClass(), TheFlowListener.class);
    if (theFlowListenerAnnotation == null) {
        throw new IllegalArgumentException("@ListenNodeDecided只能标注在特定流程监听器(@TheFlowListener)的方法上");
    }
    // 校验入参
    Class[] parameterTypes = listenMethod.getParameterTypes();
    if (parameterTypes.length != 2) {
        throw new RuntimeException("监听节点选择方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(String, TargetContext)");
    }
    if (parameterTypes[0] != String.class || parameterTypes[1] != TargetContext.class) {
        throw new RuntimeException("监听节点选择方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(String, TargetContext)");
    }
    eventType = new TheFlowEventType(theFlowListenerAnnotation.flow(), NodeDecidedEvent.class);
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:17,代码来源:ListenNodeDecidedResolver.java

示例4: init

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public void init(Method listenMethod) {
    TheFlowListener theFlowListenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod.getDeclaringClass(), TheFlowListener.class);
    if (theFlowListenerAnnotation == null) {
        throw new IllegalArgumentException("@ListenFlowException只能标注在特定流程监听器(@TheFlowListener)的方法上");
    }
    // 校验入参
    Class[] parameterTypes = listenMethod.getParameterTypes();
    if (parameterTypes.length != 2) {
        throw new RuntimeException("监听流程异常方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(Throwable, TargetContext)");
    }
    if (parameterTypes[0] != Throwable.class || parameterTypes[1] != TargetContext.class) {
        throw new RuntimeException("监听流程异常方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(Throwable, TargetContext)");
    }
    eventType = new TheFlowEventType(theFlowListenerAnnotation.flow(), FlowExceptionEvent.class);
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:17,代码来源:ListenFlowExceptionResolver.java

示例5: parseListener

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
/**
 * 解析监听器
 *
 * @param listener 监听器
 * @return 监听器执行器
 */
public static ListenerExecutor parseListener(Object listener) {
    // 获取目标class(应对AOP代理情况)
    Class<?> listenerClass = AopUtils.getTargetClass(listener);
    logger.debug("解析监听器:{}", ClassUtils.getQualifiedName(listenerClass));
    // 此处得到的@Listener是已经经过@AliasFor属性别名进行属性同步后的结果
    Listener listenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenerClass, Listener.class);
    // 创建监听器执行器
    ListenerExecutor listenerExecutor = new ListenerExecutor(listener, listenerAnnotation.type(), listenerAnnotation.priority(), parseEventTypeResolver(listenerAnnotation.type()));
    for (Method method : listenerClass.getDeclaredMethods()) {
        Listen listenAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, Listen.class);
        if (listenAnnotation != null) {
            ListenExecutor listenExecutor = parseListen(listenAnnotation, method);
            listenerExecutor.addListenExecutor(listenExecutor);
        }
    }
    listenerExecutor.validate();

    return listenerExecutor;
}
 
开发者ID:zhongxunking,项目名称:bekit,代码行数:26,代码来源:ListenerParser.java

示例6: createWxMappingInfo

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
private WxMappingInfo createWxMappingInfo(AnnotatedElement element) {
    WxButton wxButton = AnnotatedElementUtils.findMergedAnnotation(element, WxButton.class);
    // 由于这个机制,所以无法为同一个方法绑定多个WxButton、WxEventMapping、WxMessageMapping
    if (wxButton != null) {
        return createWxButtonMappingInfo(wxButton);
    }
    WxMessageMapping wxMessageMapping = AnnotatedElementUtils.findMergedAnnotation(element, WxMessageMapping.class);
    if (wxMessageMapping != null) {
        return createWxMessageMappingInfo(wxMessageMapping);
    }
    WxEventMapping wxEventMapping = AnnotatedElementUtils.findMergedAnnotation(element, WxEventMapping.class);
    if (wxEventMapping != null) {
        return createWxEventMappingInfo(wxEventMapping);
    }
    return null;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:17,代码来源:WxMappingHandlerMapping.java

示例7: init

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public void init(Method listenMethod) {
    ConfigListener configListenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod.getDeclaringClass(), ConfigListener.class);
    if (configListenerAnnotation == null) {
        throw new IllegalArgumentException("@ListenConfigModified只能标注在配置监听器(@ConfigListener)的方法上");
    }
    // 校验入参
    Class[] parameterTypes = listenMethod.getParameterTypes();
    if (parameterTypes.length != 1) {
        throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
    }
    if (parameterTypes[0] != List.class) {
        throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
    }
    ResolvableType resolvableType = ResolvableType.forMethodParameter(listenMethod, 0);
    if (resolvableType.getGeneric(0).resolve(Object.class) != ModifiedProperty.class) {
        throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
    }
    // 设置事件类型
    ListenConfigModified listenConfigModifiedAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod, ListenConfigModified.class);
    eventType = new ConfigModifiedEventType(configListenerAnnotation.configContextName(), listenConfigModifiedAnnotation.prefix());
}
 
开发者ID:zhongxunking,项目名称:configcenter,代码行数:23,代码来源:ListenConfigModifiedResolver.java

示例8: getMappingForMethod

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				new RequestMethodsRequestCondition(annotation.method()),
				new ParamsRequestCondition(annotation.params()),
				new HeadersRequestCondition(annotation.headers()),
				new ConsumesRequestCondition(annotation.consumes(), annotation.headers()),
				new ProducesRequestCondition(annotation.produces(), annotation.headers()), null);
	}
	else {
		return null;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:CrossOriginTests.java

示例9: retrieveConfigurationAttributes

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
/**
 * Retrieve the {@link TransactionConfigurationAttributes} for the
 * supplied {@link TestContext} whose {@linkplain Class test class}
 * may optionally declare or inherit
 * {@link TransactionConfiguration @TransactionConfiguration}.
 * <p>If {@code @TransactionConfiguration} is not present for the
 * supplied {@code TestContext}, a default instance of
 * {@code TransactionConfigurationAttributes} will be used instead.
 * @param testContext the test context for which the configuration
 * attributes should be retrieved
 * @return the TransactionConfigurationAttributes instance for this listener,
 * potentially cached
 * @see TransactionConfigurationAttributes#TransactionConfigurationAttributes()
 */
@SuppressWarnings("deprecation")
TransactionConfigurationAttributes retrieveConfigurationAttributes(TestContext testContext) {
	if (this.configurationAttributes == null) {
		Class<?> clazz = testContext.getTestClass();

		TransactionConfiguration txConfig = AnnotatedElementUtils.findMergedAnnotation(clazz,
			TransactionConfiguration.class);
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("Retrieved @TransactionConfiguration [%s] for test class [%s].",
				txConfig, clazz.getName()));
		}

		TransactionConfigurationAttributes configAttributes = (txConfig == null ? defaultTxConfigAttributes
				: new TransactionConfigurationAttributes(txConfig.transactionManager(), txConfig.defaultRollback()));

		if (logger.isDebugEnabled()) {
			logger.debug(String.format("Using TransactionConfigurationAttributes %s for test class [%s].",
				configAttributes, clazz.getName()));
		}
		this.configurationAttributes = configAttributes;
	}
	return this.configurationAttributes;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:TransactionalTestExecutionListener.java

示例10: beforeOrAfterTestClass

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
/**
 * Perform the actual work for {@link #beforeTestClass} and {@link #afterTestClass}
 * by dirtying the context if appropriate (i.e., according to the required mode).
 * @param testContext the test context whose application context should
 * potentially be marked as dirty; never {@code null}
 * @param requiredClassMode the class mode required for a context to
 * be marked dirty in the current phase; never {@code null}
 * @throws Exception allows any exception to propagate
 * @since 4.2
 * @see #dirtyContext
 */
protected void beforeOrAfterTestClass(TestContext testContext, ClassMode requiredClassMode) throws Exception {
	Assert.notNull(testContext, "TestContext must not be null");
	Assert.notNull(requiredClassMode, "requiredClassMode must not be null");

	Class<?> testClass = testContext.getTestClass();
	Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");

	DirtiesContext dirtiesContext = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
	boolean classAnnotated = (dirtiesContext != null);
	ClassMode classMode = (classAnnotated ? dirtiesContext.classMode() : null);

	if (logger.isDebugEnabled()) {
		String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
		logger.debug(String.format(
			"%s test class: context %s, class annotated with @DirtiesContext [%s] with mode [%s].", phase,
			testContext, classAnnotated, classMode));
	}

	if (classMode == requiredClassMode) {
		dirtyContext(testContext, dirtiesContext.hierarchyMode());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:AbstractDirtiesContextTestExecutionListener.java

示例11: ServiceMethodInfo

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
public ServiceMethodInfo(Method method) {
	this.method = method;
	ReactiveSocket annotated = AnnotatedElementUtils.findMergedAnnotation(method, ReactiveSocket.class);
	if(annotated == null){
		throw new IllegalStateException("Service methods must be annotated with a one of {@OneWayMapping, @RequestOneMapping, @RequestManyMapping, @RequestStreamMapping} ");
	}
	this.mappingInfo = new ServiceMappingInfo(annotated.value(), annotated.mimeType(), annotated.exchangeMode());
	this.returnType = ResolvableType.forMethodReturnType(method);
	findPayloadParameter();
	validate();

}
 
开发者ID:viniciusccarvalho,项目名称:spring-cloud-sockets,代码行数:13,代码来源:ServiceMethodInfo.java

示例12: createContextCustomizer

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
    AutoConfigureEmbeddedDatabase databaseAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, AutoConfigureEmbeddedDatabase.class);

    if (databaseAnnotation != null
            && databaseAnnotation.type() == EmbeddedDatabaseType.POSTGRES
            && databaseAnnotation.replace() != Replace.NONE) {
        return new PreloadableEmbeddedPostgresContextCustomizer(databaseAnnotation);
    }

    return null;
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:13,代码来源:EmbeddedPostgresContextCustomizerFactory.java

示例13: getPathUrl

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
/**
 * Url获取函数,作为函数传入StorageService。
 * @param path
 * @return FileInfo
 */
public static String getPathUrl(Path path) {
    String resourcePath = path.getName(0).relativize(path).toString().replace("\\", "/");
    String methodName = path.toFile().isDirectory() ? "viewDir" : "serveFile";
    Method method;
    try {
        method = FileServerEndpoint.class.getDeclaredMethod(methodName, HttpServletRequest.class);
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException("No " + methodName + " method in " + FileServerEndpoint.class.getSimpleName());
    }

    String methodPath;
    RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);

    if (requestMapping == null) {
        throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
    }
    String[] paths = requestMapping.path();
    if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
        methodPath = "/";
    }else {
        methodPath = paths[0].substring(0, paths[0].length() - 2);
    }

    String baseUrl = MvcUriComponentsBuilder
            .fromController(FileServerEndpoint.class)
            .build().toString();

    String pathUrl = baseUrl + methodPath + resourcePath;

    return pathUrl;
}
 
开发者ID:chaokunyang,项目名称:amanda,代码行数:37,代码来源:FileServerUtil.java

示例14: getMergedOrDefaultAnnotationValue

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
@SuppressWarnings( {"rawtypes", "unchecked"})
private <T> T getMergedOrDefaultAnnotationValue(String attribute, Class annotationType, Class<T> targetType) {
  Annotation annotation = AnnotatedElementUtils.findMergedAnnotation(method, annotationType);
  if (annotation == null) {
    return targetType.cast(AnnotationUtils.getDefaultValue(annotationType, attribute));
  }

  return targetType.cast(AnnotationUtils.getValue(annotation, attribute));
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:10,代码来源:EbeanQueryMethod.java

示例15: WxApiTypeInfo

import org.springframework.core.annotation.AnnotatedElementUtils; //导入方法依赖的package包/类
/**
 * @param clazz       代理类
 * @param defaultHost 默认host
 */
public WxApiTypeInfo(Class clazz, String defaultHost) {
    this.clazz = clazz;
    WxApiRequest wxApiRequest = AnnotatedElementUtils.findMergedAnnotation(clazz, WxApiRequest.class);
    String host = getTypeWxApiHost(wxApiRequest, defaultHost);
    String typePath = getTypeWxApiRequestPath(wxApiRequest);
    // 固定https请求
    propertyPrefix = getTypeWxApiPropertyPrefix(wxApiRequest);
    baseBuilder = UriComponentsBuilder.newInstance().scheme("https").host(host).path(typePath);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:14,代码来源:WxApiTypeInfo.java


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