org.springframework.core.annotation.AnnotatedElementUtils Java Examples
The following examples show how to use
org.springframework.core.annotation.AnnotatedElementUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DelegatingMethodParameter.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Customize method parameter [ ]. * * @param pNames the p names * @param parameters the parameters * @return the method parameter [ ] */ public static MethodParameter[] customize(String[] pNames, MethodParameter[] parameters) { List<MethodParameter> explodedParameters = new ArrayList<>(); for (int i = 0; i < parameters.length; ++i) { MethodParameter p = parameters[i]; Class<?> paramClass = AdditionalModelsConverter.getReplacement(p.getParameterType()); if (p.hasParameterAnnotation(ParameterObject.class) || AnnotatedElementUtils.isAnnotated(paramClass, ParameterObject.class)) { MethodParameterPojoExtractor.extractFrom(paramClass).forEach(explodedParameters::add); } else { String name = pNames != null ? pNames[i] : p.getParameterName(); explodedParameters.add(new DelegatingMethodParameter(p, name, null,false)); } } return explodedParameters.toArray(new MethodParameter[0]); }
Example #2
Source File: AbstractDirtiesContextTestExecutionListener.java From spring-analysis-note with MIT License | 6 votes |
/** * 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()); } }
Example #3
Source File: SpringMethodFilter.java From RestDoc with Apache License 2.0 | 6 votes |
@Override public boolean isSupport(Method method) { if (method.isSynthetic() || method.isBridge()) return false; // 如果方法和类上都没有ResponseBody,返回false if (!AnnotatedElementUtils.hasAnnotation(method, ResponseBody.class) && !AnnotatedElementUtils.hasAnnotation(method.getDeclaringClass(), ResponseBody.class)) { return false; } var annotations = method.getAnnotations(); for (var annotation : annotations) { var annotationType = annotation.annotationType(); if (_classes.contains(annotationType)) return true; } return false; }
Example #4
Source File: TransactionalTestExecutionListener.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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; }
Example #5
Source File: TransactionalTestExecutionListener.java From java-technology-stack with MIT License | 6 votes |
/** * Determine whether or not to rollback transactions for the supplied * {@linkplain TestContext test context} by taking into consideration the * {@linkplain #isDefaultRollback(TestContext) default rollback} flag and a * possible method-level override via the {@link Rollback @Rollback} * annotation. * @param testContext the test context for which the rollback flag * should be retrieved * @return the <em>rollback</em> flag for the supplied test context * @throws Exception if an error occurs while determining the rollback flag */ protected final boolean isRollback(TestContext testContext) throws Exception { boolean rollback = isDefaultRollback(testContext); Rollback rollbackAnnotation = AnnotatedElementUtils.findMergedAnnotation(testContext.getTestMethod(), Rollback.class); if (rollbackAnnotation != null) { boolean rollbackOverride = rollbackAnnotation.value(); if (logger.isDebugEnabled()) { logger.debug(String.format( "Method-level @Rollback(%s) overrides default rollback [%s] for test context %s.", rollbackOverride, rollback, testContext)); } rollback = rollbackOverride; } else { if (logger.isDebugEnabled()) { logger.debug(String.format( "No method-level @Rollback override: using default rollback [%s] for test context %s.", rollback, testContext)); } } return rollback; }
Example #6
Source File: StandardAnnotationMetadata.java From lams with GNU General Public License v2.0 | 6 votes |
@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); } }
Example #7
Source File: StreamListenerAnnotationBeanPostProcessor.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Override public final Object postProcessAfterInitialization(Object bean, final String beanName) throws BeansException { Class<?> targetClass = AopUtils.isAopProxy(bean) ? AopUtils.getTargetClass(bean) : bean.getClass(); Method[] uniqueDeclaredMethods = ReflectionUtils .getUniqueDeclaredMethods(targetClass); for (Method method : uniqueDeclaredMethods) { StreamListener streamListener = AnnotatedElementUtils .findMergedAnnotation(method, StreamListener.class); if (streamListener != null && !method.isBridge()) { this.streamListenerPresent = true; this.streamListenerCallbacks.add(() -> { Assert.isTrue(method.getAnnotation(Input.class) == null, StreamListenerErrorMessages.INPUT_AT_STREAM_LISTENER); this.doPostProcess(streamListener, method, bean); }); } } return bean; }
Example #8
Source File: RequestMappingHandlerMapping.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(handlerMethod.getBeanType(), CrossOrigin.class); CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class); if (typeAnnotation == null && methodAnnotation == null) { return null; } CorsConfiguration config = new CorsConfiguration(); updateCorsConfig(config, typeAnnotation); updateCorsConfig(config, methodAnnotation); if (CollectionUtils.isEmpty(config.getAllowedMethods())) { for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) { config.addAllowedMethod(allowedMethod.name()); } } return config.applyPermitDefaultValues(); }
Example #9
Source File: ProfileValueChecker.java From spring-analysis-note with MIT License | 6 votes |
/** * Determine if the test specified by arguments to the * {@linkplain #ProfileValueChecker constructor} is <em>enabled</em> in * the current environment, as configured via the {@link IfProfileValue * @IfProfileValue} annotation. * <p>If the test is not annotated with {@code @IfProfileValue} it is * considered enabled. * <p>If a test is not enabled, this method will abort further evaluation * of the execution chain with a failed assumption; otherwise, this method * will simply evaluate the next {@link Statement} in the execution chain. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) * @throws AssumptionViolatedException if the test is disabled * @throws Throwable if evaluation of the next statement fails */ @Override public void evaluate() throws Throwable { if (this.testMethod == null) { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) { Annotation ann = AnnotatedElementUtils.findMergedAnnotation(this.testClass, IfProfileValue.class); throw new AssumptionViolatedException(String.format( "Profile configured via [%s] is not enabled in this environment for test class [%s].", ann, this.testClass.getName())); } } else { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) { throw new AssumptionViolatedException(String.format( "Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].", this.testMethod)); } } this.next.evaluate(); }
Example #10
Source File: ClassUtil.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
/** * 获取Annotation * * @param method Method * @param annotationType 注解类 * @param <A> 泛型标记 * @return {Annotation} */ public <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) { Class<?> targetClass = method.getDeclaringClass(); // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = ClassUtil.getMostSpecificMethod(method, targetClass); // If we are dealing with method with generic parameters, find the original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); // 先找方法,再找方法上的类 A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType); if (null != annotation) { return annotation; } // 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类 return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType); }
Example #11
Source File: ResponseStatusExceptionResolver.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable protected ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { if (ex instanceof ResponseStatusException) { return resolveResponseStatusException((ResponseStatusException) ex, request, response, handler); } ResponseStatus status = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class); if (status != null) { return resolveResponseStatus(status, request, response, handler, ex); } if (ex.getCause() instanceof Exception) { return doResolveException(request, response, handler, (Exception) ex.getCause()); } } catch (Exception resolveEx) { if (logger.isWarnEnabled()) { logger.warn("Failure while trying to resolve exception [" + ex.getClass().getName() + "]", resolveEx); } } return null; }
Example #12
Source File: CrossOriginTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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; } }
Example #13
Source File: LineMessageHandlerSupport.java From line-bot-sdk-java with Apache License 2.0 | 6 votes |
private HandlerMethod getMethodHandlerMethodFunction(Object consumer, Method method) { final EventMapping mapping = AnnotatedElementUtils.getMergedAnnotation(method, EventMapping.class); if (mapping == null) { return null; } Preconditions.checkState(method.getParameterCount() == 1, "Number of parameter should be 1. But {}", (Object[]) method.getParameterTypes()); // TODO: Support more than 1 argument. Like MVC's argument resolver? final Type type = method.getGenericParameterTypes()[0]; final Predicate<Event> predicate = new EventPredicate(type); return new HandlerMethod(predicate, consumer, method, getPriority(mapping, type)); }
Example #14
Source File: SimpleListenerFactory.java From rocketmq-spring-boot-starter with Apache License 2.0 | 5 votes |
void resolveListenerMethod() { context.getBeansWithAnnotation(RocketMQListener.class).forEach((beanName, obj) -> { Map<Method, RocketMQMessage> annotatedMethods = MethodIntrospector.selectMethods(obj.getClass(), (MethodIntrospector.MetadataLookup<RocketMQMessage>) method -> AnnotatedElementUtils .findMergedAnnotation(method, RocketMQMessage.class)); initSubscriptionGroup(annotatedMethods, obj); }); this.initSubscription = true; }
Example #15
Source File: WebTestContextBootstrapper.java From java-technology-stack with MIT License | 5 votes |
/** * Returns {@link WebDelegatingSmartContextLoader} if the supplied class is * annotated with {@link WebAppConfiguration @WebAppConfiguration} and * otherwise delegates to the superclass. */ @Override protected Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) { if (AnnotatedElementUtils.hasAnnotation(testClass, WebAppConfiguration.class)) { return WebDelegatingSmartContextLoader.class; } else { return super.getDefaultContextLoaderClass(testClass); } }
Example #16
Source File: HandlerMethod.java From java-technology-stack with MIT License | 5 votes |
private void evaluateResponseStatus() { ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class); if (annotation == null) { annotation = AnnotatedElementUtils.findMergedAnnotation(getBeanType(), ResponseStatus.class); } if (annotation != null) { this.responseStatus = annotation.code(); this.responseStatusReason = annotation.reason(); } }
Example #17
Source File: MvcUriComponentsBuilder.java From spring4-understanding with Apache License 2.0 | 5 votes |
private static String getTypeRequestMapping(Class<?> controllerType) { Assert.notNull(controllerType, "'controllerType' must not be null"); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class); if (requestMapping == null) { return "/"; } String[] paths = requestMapping.path(); if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { return "/"; } if (paths.length > 1 && logger.isWarnEnabled()) { logger.warn("Multiple paths on controller " + controllerType.getName() + ", using first one"); } return paths[0]; }
Example #18
Source File: SpringTransactionAnnotationParser.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( element, Transactional.class, false, false); if (attributes != null) { return parseTransactionAnnotation(attributes); } else { return null; } }
Example #19
Source File: ControllerAdviceBean.java From lams with GNU General Public License v2.0 | 5 votes |
private ControllerAdviceBean(Object bean, BeanFactory beanFactory) { this.bean = bean; this.beanFactory = beanFactory; Class<?> beanType; if (bean instanceof String) { String beanName = (String) bean; Assert.hasText(beanName, "Bean name must not be null"); Assert.notNull(beanFactory, "BeanFactory must not be null"); if (!beanFactory.containsBean(beanName)) { throw new IllegalArgumentException("BeanFactory [" + beanFactory + "] does not contain specified controller advice bean '" + beanName + "'"); } beanType = this.beanFactory.getType(beanName); this.order = initOrderFromBeanType(beanType); } else { Assert.notNull(bean, "Bean must not be null"); beanType = bean.getClass(); this.order = initOrderFromBean(bean); } ControllerAdvice annotation = AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class); if (annotation != null) { this.basePackages = initBasePackages(annotation); this.assignableTypes = Arrays.asList(annotation.assignableTypes()); this.annotations = Arrays.asList(annotation.annotations()); } else { this.basePackages = Collections.emptySet(); this.assignableTypes = Collections.emptyList(); this.annotations = Collections.emptyList(); } }
Example #20
Source File: OpenFeignSpringMvcContract.java From summerframework with Apache License 2.0 | 5 votes |
private String defaultValue(Method method, String pathVariable) { Set<ApiImplicitParam> apiImplicitParams = AnnotatedElementUtils.findAllMergedAnnotations(method, ApiImplicitParam.class); for (ApiImplicitParam apiImplicitParam : apiImplicitParams) { if (pathVariable.equals(apiImplicitParam.name())) { return apiImplicitParam.allowableValues().split(",")[0].trim(); } } throw new IllegalArgumentException("no default value for " + pathVariable); }
Example #21
Source File: TypeDescriptor.java From spring-analysis-note with MIT License | 5 votes |
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
Example #22
Source File: AutowiredAnnotationBeanPostProcessor.java From lams with GNU General Public License v2.0 | 5 votes |
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) { if (ao.getAnnotations().length > 0) { for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) { AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type); if (attributes != null) { return attributes; } } } return null; }
Example #23
Source File: ResponseBodyResultHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override public boolean supports(HandlerResult result) { MethodParameter returnType = result.getReturnTypeSource(); Class<?> containingClass = returnType.getContainingClass(); return (AnnotatedElementUtils.hasAnnotation(containingClass, ResponseBody.class) || returnType.hasMethodAnnotation(ResponseBody.class)); }
Example #24
Source File: AbstractDirtiesContextTestExecutionListener.java From java-technology-stack with MIT License | 5 votes |
/** * Perform the actual work for {@link #beforeTestMethod} and {@link #afterTestMethod} * by dirtying the context if appropriate (i.e., according to the required modes). * @param testContext the test context whose application context should * potentially be marked as dirty; never {@code null} * @param requiredMethodMode the method mode required for a context to * be marked dirty in the current phase; 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 beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode, ClassMode requiredClassMode) throws Exception { Assert.notNull(testContext, "TestContext must not be null"); Assert.notNull(requiredMethodMode, "requiredMethodMode must not be null"); Assert.notNull(requiredClassMode, "requiredClassMode must not be null"); Class<?> testClass = testContext.getTestClass(); Method testMethod = testContext.getTestMethod(); Assert.notNull(testClass, "The test class of the supplied TestContext must not be null"); Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null"); DirtiesContext methodAnn = AnnotatedElementUtils.findMergedAnnotation(testMethod, DirtiesContext.class); DirtiesContext classAnn = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class); boolean methodAnnotated = (methodAnn != null); boolean classAnnotated = (classAnn != null); MethodMode methodMode = (methodAnnotated ? methodAnn.methodMode() : null); ClassMode classMode = (classAnnotated ? classAnn.classMode() : null); if (logger.isDebugEnabled()) { String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After"); logger.debug(String.format("%s test method: context %s, class annotated with @DirtiesContext [%s] " + "with mode [%s], method annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext, classAnnotated, classMode, methodAnnotated, methodMode)); } if ((methodMode == requiredMethodMode) || (classMode == requiredClassMode)) { HierarchyMode hierarchyMode = (methodAnnotated ? methodAnn.hierarchyMode() : classAnn.hierarchyMode()); dirtyContext(testContext, hierarchyMode); } }
Example #25
Source File: WebFluxResponseStatusExceptionHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable protected HttpStatus determineStatus(Throwable ex) { HttpStatus status = super.determineStatus(ex); if (status == null) { ResponseStatus ann = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class); if (ann != null) { status = ann.code(); } } return status; }
Example #26
Source File: AbstractRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets api parameters. * * @param method the method * @return the api parameters */ private Map<String, io.swagger.v3.oas.annotations.Parameter> getApiParameters(Method method) { Class<?> declaringClass = method.getDeclaringClass(); Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDoc = AnnotatedElementUtils .findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameters.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersMap = apiParametersDoc.stream() .flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameters.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass.stream() .flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParametersDocDeclaringClassMap); Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDoc = AnnotatedElementUtils .findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameter.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocMap = apiParameterDoc.stream() .collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParameterDocMap); Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameter.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass.stream() .collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParameterDocDeclaringClassMap); return apiParametersMap; }
Example #27
Source File: WxMappingHandlerMapping.java From FastBootWeixin with Apache License 2.0 | 5 votes |
@Override protected HandlerMethod createHandlerMethod(Object handler, Method method) { if (handler instanceof String) { String beanName = (String) handler; handler = this.getApplicationContext().getAutowireCapableBeanFactory().getBean(beanName); } if (AnnotatedElementUtils.hasAnnotation(method, WxAsyncMessage.class) || AnnotatedElementUtils.hasAnnotation(handler.getClass(), WxAsyncMessage.class)) { return new HandlerMethod(wxAsyncHandlerFactory.createHandler(handler), method); } else { return new HandlerMethod(handler, method); } }
Example #28
Source File: BeanAnnotationHelper.java From spring-analysis-note with MIT License | 5 votes |
public static boolean isScopedProxy(Method beanMethod) { Boolean scopedProxy = scopedProxyCache.get(beanMethod); if (scopedProxy == null) { AnnotationAttributes scope = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Scope.class, false, false); scopedProxy = (scope != null && scope.getEnum("proxyMode") != ScopedProxyMode.NO); scopedProxyCache.put(beanMethod, scopedProxy); } return scopedProxy; }
Example #29
Source File: SecurityParser.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Get security requirements io . swagger . v 3 . oas . annotations . security . security requirement [ ]. * * @param method the method * @return the io . swagger . v 3 . oas . annotations . security . security requirement [ ] */ public io.swagger.v3.oas.annotations.security.SecurityRequirement[] getSecurityRequirements( HandlerMethod method) { // class SecurityRequirements io.swagger.v3.oas.annotations.security.SecurityRequirements classSecurity = AnnotatedElementUtils.findMergedAnnotation(method.getBeanType(), io.swagger.v3.oas.annotations.security.SecurityRequirements.class); // method SecurityRequirements io.swagger.v3.oas.annotations.security.SecurityRequirements methodSecurity = AnnotatedElementUtils.findMergedAnnotation(method.getMethod(), io.swagger.v3.oas.annotations.security.SecurityRequirements.class); Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> allSecurityTags = null; if (classSecurity != null) allSecurityTags = new HashSet<>(Arrays.asList(classSecurity.value())); if (methodSecurity != null) allSecurityTags = addSecurityRequirements(allSecurityTags, new HashSet<>(Arrays.asList(methodSecurity.value()))); if (CollectionUtils.isEmpty(allSecurityTags)) { // class SecurityRequirement Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> securityRequirementsClassList = AnnotatedElementUtils.findMergedRepeatableAnnotations( method.getBeanType(), io.swagger.v3.oas.annotations.security.SecurityRequirement.class); // method SecurityRequirement Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> securityRequirementsMethodList = AnnotatedElementUtils.findMergedRepeatableAnnotations(method.getMethod(), io.swagger.v3.oas.annotations.security.SecurityRequirement.class); if (!CollectionUtils.isEmpty(securityRequirementsClassList)) allSecurityTags = addSecurityRequirements(allSecurityTags, securityRequirementsClassList); if (!CollectionUtils.isEmpty(securityRequirementsMethodList)) allSecurityTags = addSecurityRequirements(allSecurityTags, securityRequirementsMethodList); } return (allSecurityTags != null) ? allSecurityTags.toArray(new io.swagger.v3.oas.annotations.security.SecurityRequirement[0]) : null; }
Example #30
Source File: ApplicationListenerMethodTransactionalAdapter.java From java-technology-stack with MIT License | 5 votes |
public ApplicationListenerMethodTransactionalAdapter(String beanName, Class<?> targetClass, Method method) { super(beanName, targetClass, method); TransactionalEventListener ann = AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class); if (ann == null) { throw new IllegalStateException("No TransactionalEventListener annotation found on method: " + method); } this.annotation = ann; }