@Test public void customFiltersFollowedByResetUseIndex() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER)); provider.addIncludeFilter(new AnnotationTypeFilter(Component.class)); provider.resetFilters(true); Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE); assertBeanDefinitionType(candidates, AnnotatedGenericBeanDefinition.class); }
void init() throws ClassNotFoundException, InstantiationException, IllegalAccessException { Set<APIEvent> boundEvents = new HashSet<APIEvent>(100); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true); scanner.resetFilters(false); scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class)); for (String pkg : getBasePkgNames()) { for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) { Class<?> clazz = Class.forName(bd.getBeanClassName()); if (clazz == APIEvent.class) { continue; } APIEvent evt = (APIEvent) clazz.newInstance(); boundEvents.add(evt); } } for (APIEvent e : boundEvents) { bus.subscribeEvent(this, e); } }
synchronized Set<BeanDefinition> findCandidateBeans(String scanBase, Class<? extends Annotation> annotatedClass) { provider.resetFilters(false); provider.addIncludeFilter(new AnnotatedMethodFilter(annotatedClass)); String basePackage = scanBase.replace('.', '/'); return provider.findCandidateComponents(basePackage); } }