本文整理汇总了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;
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}