List of usage examples for org.springframework.core.type AnnotationMetadata hasAnnotatedMethods
default boolean hasAnnotatedMethods(String annotationName)
From source file:com.reactivetechnologies.platform.utils.EntityFinder.java
/** * Scans for JAX RS classes under given (comma delimited) packages * @param basePkg/*from ww w. j a v a2 s . co m*/ * @return * @throws ClassNotFoundException * @throws IllegalAccessException */ public static List<Class<?>> findJaxRsClasses(String basePkg) throws ClassNotFoundException, IllegalAccessException { if (basePkg.contains(",")) { List<Class<?>> allPkgClasses = new ArrayList<>(); String[] pkgs = basePkg.split(","); for (String pkg : pkgs) { allPkgClasses.addAll(findJaxRsClasses(pkg)); } return allPkgClasses; } ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false); provider.addIncludeFilter(new TypeFilter() { @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { AnnotationMetadata aMeta = metadataReader.getAnnotationMetadata(); return aMeta.hasAnnotation(Path.class.getName()) || (aMeta.hasAnnotatedMethods(GET.class.getName()) || aMeta.hasAnnotatedMethods(POST.class.getName()) || aMeta.hasAnnotatedMethods(DELETE.class.getName()) || aMeta.hasAnnotatedMethods(Path.class.getName())); } }); Set<BeanDefinition> beans = null; try { beans = provider.findCandidateComponents(StringUtils.hasText(basePkg) ? basePkg : EntityFinder.class.getName().substring(0, EntityFinder.class.getName().lastIndexOf("."))); } catch (Exception e) { throw new BeanInitializationException("Unable to scan for JAX-RS annotated classes under base package", e); } List<Class<?>> classes = new ArrayList<Class<?>>(); if (beans != null && !beans.isEmpty()) { Class<?> restletClass; for (BeanDefinition bd : beans) { restletClass = Class.forName(bd.getBeanClassName()); classes.add(restletClass); } } else { log.warn("** Did not find any JAX-RS annotated classes under the given base scan package [" + basePkg + "]. No REST requests will be served **"); } return classes; }
From source file:com.github.yulechen.springannotation.test.ConfigurationClassUtils.java
/** * Check the given metadata for a lite configuration class candidate (e.g. a * class annotated with {@code @Component} or just having {@code @Import} * declarations or {@code @Bean methods}). * /*from w w w .j a v a2 s . c om*/ * @param metadata * the metadata of the annotated class * @return {@code true} if the given class is to be processed as a lite * configuration class, just registering it and scanning it for * {@code @Bean} methods */ public static boolean isLiteConfigurationCandidate(AnnotationMetadata metadata) { // Do not consider an interface or an annotation... if (metadata.isInterface()) { return false; } // Any of the typical annotations found? for (String indicator : candidateIndicators) { if (metadata.isAnnotated(indicator)) { return true; } } // Finally, let's look for @Bean methods... try { return metadata.hasAnnotatedMethods(Bean.class.getName()); } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug( "Failed to introspect @Bean methods on class [" + metadata.getClassName() + "]: " + ex); } return false; } }
From source file:org.duracloud.account.db.util.security.impl.AnnotationParserImpl.java
private boolean hasAnnotatedMethods(Class annotationClass, Class targetClass) { MetadataReader metadataReader = getMetadataReader(targetClass); AnnotationMetadata annotationMd = metadataReader.getAnnotationMetadata(); return annotationMd.hasAnnotatedMethods(annotationClass.getName()); }
From source file:io.neba.core.selftests.SelftestRegistrar.java
private boolean isSelftestingBean(AnnotationMetadata metadata) { return metadata.hasAnnotatedMethods(this.selftestAnnotationName); }
From source file:org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.java
/** * Determine whether the given bean definition qualifies as candidate. * <p>The default implementation checks whether the class is not an interface * and not dependent on an enclosing class. * <p>Can be overridden in subclasses. * @param beanDefinition the bean definition to check * @return whether the bean definition qualifies as a candidate component *//*from w w w. java2 s . c o m*/ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { AnnotationMetadata metadata = beanDefinition.getMetadata(); return (metadata.isIndependent() && (metadata.isConcrete() || (metadata.isAbstract() && metadata.hasAnnotatedMethods(Lookup.class.getName())))); }