本文整理汇总了Java中org.springframework.core.annotation.AnnotatedElementUtils类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedElementUtils类的具体用法?Java AnnotatedElementUtils怎么用?Java AnnotatedElementUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedElementUtils类属于org.springframework.core.annotation包,在下文中一共展示了AnnotatedElementUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.springframework.core.annotation.AnnotatedElementUtils; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.applicationContext, Object.class);
for(String beanName : beanNames){
Class<?> beanType = this.applicationContext.getType(beanName);
if(beanType != null){
final Class<?> userType = ClassUtils.getUserClass(beanType);
ReflectionUtils.doWithMethods(userType, method -> {
if(AnnotatedElementUtils.findMergedAnnotation(method, ReactiveSocket.class) != null) {
ServiceMethodInfo info = new ServiceMethodInfo(method);
logger.info("Registering remote endpoint at path {}, exchange {} for method {}", info.getMappingInfo().getPath(), info.getMappingInfo().getExchangeMode(), method);
MethodHandler methodHandler = new MethodHandler(applicationContext.getBean(beanName), info);
mappingHandlers.add(methodHandler);
}
});
}
}
initDefaultConverters();
}
示例2: postProcessAfterInitialization
import org.springframework.core.annotation.AnnotatedElementUtils; //导入依赖的package包/类
/**
* The method scans all beans, that contain methods,
* annotated as {@link ScheduledBeanMethod}
*/
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
Map<Method, Set<ScheduledBeanMethod>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
(MethodIntrospector.MetadataLookup<Set<ScheduledBeanMethod>>) method -> {
Set<ScheduledBeanMethod> scheduledMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations(
method, ScheduledBeanMethod.class, ScheduledBeanMethods.class);
return (!scheduledMethods.isEmpty() ? scheduledMethods : null);
});
for (Map.Entry<Method, Set<ScheduledBeanMethod>> entry : annotatedMethods.entrySet()) {
scheduleAnnotatedMethods.add(new ScheduledMethodContext(beanName, entry.getKey(), entry.getValue()));
}
return bean;
}
示例3: 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
示例4: 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
示例5: 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);
}
示例6: 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);
}
示例7: 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;
}
示例8: 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;
}
示例9: 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());
}
示例10: hasAnnotatedMethods
import org.springframework.core.annotation.AnnotatedElementUtils; //导入依赖的package包/类
@Override
public boolean hasAnnotatedMethods(String annotationName) {
try {
Method[] methods = getIntrospectedClass().getDeclaredMethods();
for (Method method : methods) {
if (!method.isBridge() && method.getAnnotations().length > 0 &&
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
return true;
}
}
return false;
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
}
}
示例11: getAnnotatedMethods
import org.springframework.core.annotation.AnnotatedElementUtils; //导入依赖的package包/类
@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
try {
Method[] methods = getIntrospectedClass().getDeclaredMethods();
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
for (Method method : methods) {
if (!method.isBridge() && method.getAnnotations().length > 0 &&
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
}
}
return annotatedMethods;
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
}
}
示例12: doResolveException
import org.springframework.core.annotation.AnnotatedElementUtils; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
ResponseStatus responseStatus = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
if (responseStatus != null) {
try {
return resolveResponseStatus(responseStatus, request, response, handler, ex);
}
catch (Exception resolveEx) {
logger.warn("Handling of @ResponseStatus resulted in Exception", resolveEx);
}
}
else if (ex.getCause() instanceof Exception) {
ex = (Exception) ex.getCause();
return doResolveException(request, response, handler, ex);
}
return null;
}
示例13: 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;
}
}
示例14: 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;
}
示例15: 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