List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanNamesForAnnotation
String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);
From source file:org.jacpfx.vertx.spring.SpringSingleVerticleConfiguration.java
@Override /**/*from w w w . j a va2 s . c o m*/ * Ensure that only one spring verticle per spring context will be deployed, in case the "autoremovetherSpringVerticles" is set to true * */ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { // assume the annotation is present, otherwise hew would never call this final SpringVerticle annotation = currentSpringVerticleClass.getAnnotation(SpringVerticle.class); if (annotation.autoremoveOtherSpringVerticles()) { final String[] verticleBeanNames = beanFactory.getBeanNamesForAnnotation(SpringVerticle.class); if (verticleBeanNames.length > 1) { final List<String> beansToRemove = getBeanNamesToRemove(verticleBeanNames, beanFactory); beansToRemove.forEach(((BeanDefinitionRegistry) beanFactory)::removeBeanDefinition); } } }
From source file:lodsve.core.condition.OnBeanCondition.java
private String[] getBeanNamesForAnnotation(ConfigurableListableBeanFactory beanFactory, String type, ClassLoader classLoader, boolean considerHierarchy) throws LinkageError { String[] result = NO_BEANS;//from w w w . j a v a 2 s . c o m try { @SuppressWarnings("unchecked") Class<? extends Annotation> typeClass = (Class<? extends Annotation>) ClassUtils.forName(type, classLoader); result = beanFactory.getBeanNamesForAnnotation(typeClass); if (considerHierarchy) { if (beanFactory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) { String[] parentResult = getBeanNamesForAnnotation( (ConfigurableListableBeanFactory) beanFactory.getParentBeanFactory(), type, classLoader, true); List<String> resultList = new ArrayList<String>(); resultList.addAll(Arrays.asList(result)); for (String beanName : parentResult) { if (!resultList.contains(beanName) && !beanFactory.containsLocalBean(beanName)) { resultList.add(beanName); } } result = StringUtils.toStringArray(resultList); } } return result; } catch (ClassNotFoundException ex) { return NO_BEANS; } }