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


Java AnnotationUtils.findAnnotation方法代码示例

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


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

示例1: getProviderStateMethods

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
private Map<String, Method> getProviderStateMethods(Class<?> clazz) {
    Map<String, Method> providerStateMethods = new HashMap<>();

    for (Method method : clazz.getMethods()) {
        ProviderState annotation = AnnotationUtils.findAnnotation(method, ProviderState.class);
        if (annotation != null) {
            String state = annotation.value();
            if (StringUtils.isEmpty(state)) {
                state = method.getName();
            }
            if (providerStateMethods.containsKey(state)) {
                throw new IllegalStateException("There must be only one setup method per provider state");
            }
            providerStateMethods.put(state, method);
        }
    }

    return providerStateMethods;
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:20,代码来源:PactTestRunner.java

示例2: doAround

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@Around(value = "@annotation(com.reger.datasource.annotation.DataSourceChange)", argNames = "point")
public Object doAround(final ProceedingJoinPoint point) throws Throwable {
	MethodSignature ms = (MethodSignature) point.getSignature();
	Method method = ms.getMethod();

	Class<?> targetClass = point.getTarget().getClass();
	Method targetMethod = targetClass.getMethod(method.getName(), method.getParameterTypes());
	DataSourceChange annotation = AnnotationUtils.findAnnotation(targetMethod, DataSourceChange.class);
	if (annotation == null)
		return point.proceed();
	SwitchExecute<Object> execute= new SwitchExecute<Object>() {
		@Override
		public Object run() throws Throwable {
			return point.proceed();
		}
		 
	};
	if (annotation.slave()) {
		logger.debug("注解到从库执行");
		return Proxy.slave(execute);
	} else {
		logger.debug("注解到主库执行");
		return Proxy.master(execute);
	}
}
 
开发者ID:halober,项目名称:spring-boot-starter-dao,代码行数:26,代码来源:DataSourceAspect.java

示例3: registerFactoryMethodForConfigBean

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * 为@ConfigBean的bean注册它的Factory Method,通过静态Factory Method来创建@ConfigBean实例
 *
 * @param registry
 * @param beanName
 * @param beanDefinition
 */
private void registerFactoryMethodForConfigBean(BeanDefinitionRegistry registry, String beanName, BeanDefinition beanDefinition) {
    String beanClassName = beanDefinition.getBeanClassName();
    if (beanClassName == null) { // 通过注解@Bean声明的bean,beanClassName=null
        return;
    }

    Class<?> beanClass = ClassUtils.resolveClassName(beanClassName, beanFactory.getBeanClassLoader());
    ConfigBean config = AnnotationUtils.findAnnotation(beanClass, ConfigBean.class);
    if (config == null) {
        return;
    }

    // 为配置bean设置factory method
    String propertyName = config.value();
    ConfigBeanConfigUtils.setConfigBeanFactoryMethod(registry,
            beanName, beanDefinition, propertyName, config.converter());
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:25,代码来源:ConfigBeanPostProcessor.java

示例4: processException

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorVM> processException(Exception ex) {
    log.error(ex.getMessage(), ex);
    BodyBuilder builder;
    ErrorVM errorVM;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason());
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
    }
    return builder.body(errorVM);
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:16,代码来源:ExceptionTranslator.java

示例5: processRuntimeException

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) {
    BodyBuilder builder;
    ErrorVM errorVM;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason());
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
    }
    return builder.body(errorVM);
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:15,代码来源:ExceptionTranslator.java

示例6: getMessageResponseDTO

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
protected MessageResponseDTO getMessageResponseDTO(Exception e) {
	BusinessException businessAnnotation = AnnotationUtils.findAnnotation(e.getClass(), BusinessException.class);
	MessageResponseDTO message = new MessageResponseDTO();
	String messageKey = Optional.of(businessAnnotation.message())
						.filter(m -> !BusinessException.MESSAGE_NOT_DEFINED.equals(m))
						.orElse(Translator.getInterpoledKeyOf(e.getClass().getCanonicalName()));
	message.setKey(messageKey);
	message.setSeverity(businessAnnotation.severity());
	
	ParameterFinderStrategy parameterFinder = new GenericParameterFinder(e);
	message.setParameters(parameterFinder.findParameters());
	return message;
}
 
开发者ID:rooting-company,项目名称:roxana,代码行数:14,代码来源:BusinessExceptionResponseProcessor.java

示例7: getManagedMetric

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@Override
public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException {
	org.springframework.jmx.export.annotation.ManagedMetric ann =
			AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class);
	if (ann == null) {
		return null;
	}
	ManagedMetric managedMetric = new ManagedMetric();
	AnnotationBeanUtils.copyPropertiesToBean(ann, managedMetric);
	return managedMetric;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:AnnotationJmxAttributeSource.java

示例8: getNamesForAnnotation

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * Returns the names of beans annotated with the given {@code annotation}, judging
 * from either bean definitions or the value of {@link FactoryBean#getObjectType()} in
 * the case of {@link FactoryBean FactoryBeans}. Will include singletons but will not
 * cause early bean initialization.
 *
 * @param annotation the annotation to match (must not be {@code null})
 * @return the names of beans (or objects created by FactoryBeans) annoated with the
 * given annotation, or an empty set if none
 */
Set<String> getNamesForAnnotation(Class<? extends Annotation> annotation) {
    updateTypesIfNecessary();
    Set<String> matches = new LinkedHashSet<>();
    for (Map.Entry<String, Class<?>> entry : this.beanTypes.entrySet()) {
        if (entry.getValue() != null &&
                AnnotationUtils.findAnnotation(entry.getValue(), annotation) != null) {
            matches.add(entry.getKey());
        }
    }
    return matches;
}
 
开发者ID:drtrang,项目名称:spring-boot-autoconfigure,代码行数:22,代码来源:BeanTypeRegistry.java

示例9: afterTestClass

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@Override
public void afterTestClass(TestContext testContext) throws Exception {
    FixedClock annotation = AnnotationUtils.findAnnotation(testContext.getTestClass(), FixedClock.class);
    if (annotation == null) {
        return;
    }
    //reset(testContext.getApplicationContext().getBean(Clock.class));
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:9,代码来源:FixedClockListener.java

示例10: getManagedOperation

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@Override
public ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException {
	Annotation ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class);
	if (ann == null) {
		return null;
	}
	ManagedOperation op = new ManagedOperation();
	AnnotationBeanUtils.copyPropertiesToBean(ann, op);
	return op;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:AnnotationJmxAttributeSource.java

示例11: defaultErrorHandler

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
	// If the exception is annotated with @ResponseStatus rethrow it and let
	// the framework handle it (for personal and annotated Exception)
	if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
		throw e;
	}

	logger.error("Unhandle exception occured : " + e.getMessage(), e);

	return getMAV(req, e, HttpStatus.INTERNAL_SERVER_ERROR);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:13,代码来源:GlobalExceptionHandler.java

示例12: defaultErrorHandler

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception ex, @AuthenticationPrincipal User user) throws Exception {

  // If the exception is annotated with @ResponseStatus rethrow it and let the framework handle it
  if (AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class) != null) {
    throw ex;
  }

  Rollbar rollbar = new Rollbar(accessToken, environment.getActiveProfiles()[0])
    .platform(System.getProperty("java.version"))
    .request(new Request()
      .url(request.getRequestURL().toString())
      .method(request.getMethod())
      .headers(headers(request))
      .queryString(request.getQueryString())
      .setGet(parameters(request))
      .userIp(InetAddress.getByName(request.getRemoteAddr())));

  if (user != null) {
    rollbar = rollbar.person(new Person(Objects.toString(user.getId()))
      .email(user.getEmail()));
  }

  rollbar.error(ex);

  throw ex;
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:28,代码来源:RollbarExceptionHandler.java

示例13: beforeTestClass

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
    FixedClock classFixedClock = AnnotationUtils.findAnnotation(testContext.getTestClass(), FixedClock.class);
    if (classFixedClock == null) {
        return;
    }
    mockClock(testContext, classFixedClock);
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:9,代码来源:FixedClockListener.java

示例14: addReturnValueAsModelAttribute

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class<?> handlerType,
		Object returnValue, ExtendedModelMap implicitModel) {

	ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
	String attrName = (attr != null ? attr.value() : "");
	if ("".equals(attrName)) {
		Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
		attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
	}
	implicitModel.addAttribute(attrName, returnValue);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:HandlerMethodInvoker.java

示例15: initOrderFromBeanType

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
private static int initOrderFromBeanType(Class<?> beanType) {
	Order ann = AnnotationUtils.findAnnotation(beanType, Order.class);
	return (ann != null ? ann.value() : Ordered.LOWEST_PRECEDENCE);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:ControllerAdviceBean.java


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