@Override public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) { assertBeanFactoryActive(); return getBeanFactory().getBeanNamesForAnnotation(annotationType); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (context.getBeanFactory().getBeanNamesForAnnotation(Bar.class).length > 0) { return false; } return true; } }
@Override public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) { assertBeanFactoryActive(); return getBeanFactory().getBeanNamesForAnnotation(annotationType); }
@SuppressWarnings("unchecked") private void registerSagaBeanDefinitions(EventProcessingConfigurer configurer) { String[] sagas = beanFactory.getBeanNamesForAnnotation(Saga.class); for (String saga : sagas) { Saga sagaAnnotation = beanFactory.findAnnotationOnBean(saga, Saga.class); Class sagaType = beanFactory.getType(saga); ProcessingGroup processingGroupAnnotation = beanFactory.findAnnotationOnBean(saga, ProcessingGroup.class); if (processingGroupAnnotation != null && !"".equals(processingGroupAnnotation.value())) { configurer.assignHandlerTypesMatching(processingGroupAnnotation.value(), sagaType::equals); } configurer.registerSaga(sagaType, sagaConfigurer -> { if (sagaAnnotation != null && !"".equals(sagaAnnotation.sagaStore())) { sagaConfigurer.configureSagaStore(c -> beanFactory.getBean(sagaAnnotation.sagaStore(), SagaStore.class)); } }); } }
String[] aggregates = beanFactory.getBeanNamesForAnnotation(Aggregate.class); for (String aggregate : aggregates) { Aggregate aggregateAnnotation = beanFactory.findAnnotationOnBean(aggregate, Aggregate.class);
private Stream<AnnotationAttributes> getBeanDefinitionsForAnnotation(ConfigurableListableBeanFactory bf, Class<? extends Annotation> annotation) { return Arrays.stream(bf.getBeanNamesForAnnotation(annotation)) .map(bf::getBeanDefinition) .filter(bd -> bd instanceof AnnotatedBeanDefinition) .map(bd -> (AnnotatedBeanDefinition) bd) .map(AnnotatedBeanDefinition::getMetadata) .filter(md -> md.hasAnnotation(annotation.getName())) .map(md -> (AnnotationAttributes) md.getAnnotationAttributes(annotation.getName())); }
private Stream<AnnotationAttributes> getBeanDefinitionsForAnnotation(ConfigurableListableBeanFactory bf, Class<? extends Annotation> annotation) { return Arrays.stream(bf.getBeanNamesForAnnotation(annotation)) .map(bf::getBeanDefinition) .filter(bd -> bd instanceof AnnotatedBeanDefinition) .map(bd -> (AnnotatedBeanDefinition) bd) .map(AnnotatedBeanDefinition::getMetadata) .filter(md -> md.hasAnnotation(annotation.getName())) .map(md -> (AnnotationAttributes) md.getAnnotationAttributes(annotation.getName())); }
private void findJaxrsResourcesAndProviderClasses(ConfigurableListableBeanFactory beanFactory) { logger.debug("Finding JAX-RS resources and providers Spring bean classes"); String[] resourceBeans = beanFactory.getBeanNamesForAnnotation(Path.class); String[] providerBeans = beanFactory.getBeanNamesForAnnotation(Provider.class); if(resourceBeans != null) { for(String resourceBean : resourceBeans) { allResources.add(beanFactory.getType(resourceBean)); } } if(providerBeans != null) { for(String providerBean : providerBeans) { providers.add(beanFactory.getType(providerBean)); } } if(logger.isDebugEnabled()) { for (Object resourceClass : allResources.toArray()) { logger.debug("JAX-RS resource class found: {}", ((Class) resourceClass).getName()); } } if(logger.isDebugEnabled()) { for (Object providerClass: providers.toArray()) { logger.debug("JAX-RS provider class found: {}", ((Class) providerClass).getName()); } } }
/** {@inheritDoc} */ @Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) { for (final String beanName : beanFactory.getBeanNamesForAnnotation(Prototype.class)) { final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (!beanDefinition.isPrototype()) { log.warn("Profile action '{}' is not '{}' scope but must be, please check your configuration.", beanName, BeanDefinition.SCOPE_PROTOTYPE); beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE); } } } }
private void findJaxrsResourcesAndProviderClasses(ConfigurableListableBeanFactory beanFactory) { logger.debug("Finding JAX-RS resources and providers Spring bean classes"); String[] resourceBeans = beanFactory.getBeanNamesForAnnotation(Path.class); String[] providerBeans = beanFactory.getBeanNamesForAnnotation(Provider.class); if(resourceBeans != null) { for(String resourceBean : resourceBeans) { allResources.add(beanFactory.getType(resourceBean)); } } if(providerBeans != null) { for(String providerBean : providerBeans) { providers.add(beanFactory.getType(providerBean)); } } if(logger.isDebugEnabled()) { for (Object resourceClass : allResources.toArray()) { logger.debug("JAX-RS resource class found: {}", ((Class) resourceClass).getName()); } } if(logger.isDebugEnabled()) { for (Object providerClass: providers.toArray()) { logger.debug("JAX-RS provider class found: {}", ((Class) providerClass).getName()); } } }
@Override /** * 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); } } }
@Override public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) { assertBeanFactoryActive(); return getBeanFactory().getBeanNamesForAnnotation(annotationType); }
@Override @SuppressWarnings("unchecked") protected Object getResourceToInject(Object target, String requestingBeanName) { List<Object> providers = new ArrayList<>(); try { String componentAnnotation = TestProxyBeanPostProcessor.this.resolver.resolveStringValue("${jaxrs.annotation:de.taimos.dvalin.jaxrs.JaxRsComponent}"); Class<? extends Annotation> componentAnnotationClazz = (Class<? extends Annotation>) Class.forName(componentAnnotation); String[] beans = TestProxyBeanPostProcessor.this.beanFactory.getBeanNamesForAnnotation(componentAnnotationClazz); for (String bean : beans) { if (TestProxyBeanPostProcessor.this.beanFactory.findAnnotationOnBean(bean, Provider.class) != null) { providers.add(TestProxyBeanPostProcessor.this.beanFactory.getBean(bean)); } } } catch (Exception e) { e.printStackTrace(); } String url = TestProxyBeanPostProcessor.this.resolver.resolveStringValue("${server.url:http://localhost:${jaxrs.bindport:${svc.port:8080}}}"); return JAXRSClientFactory.create(url, this.getDependencyDescriptor().getDependencyType(), providers); } }
@Override @SuppressWarnings("unchecked") protected Object getResourceToInject(Object target, String requestingBeanName) { List<Object> providers = new ArrayList<>(); try { String componentAnnotation = TestProxyBeanPostProcessor.this.resolver.resolveStringValue("${jaxrs.annotation:de.taimos.springcxfdaemon.JaxRsComponent}"); Class<? extends Annotation> componentAnnotationClazz = (Class<? extends Annotation>) Class.forName(componentAnnotation); String[] beans = TestProxyBeanPostProcessor.this.beanFactory.getBeanNamesForAnnotation(componentAnnotationClazz); for (String bean : beans) { if (TestProxyBeanPostProcessor.this.beanFactory.findAnnotationOnBean(bean, Provider.class) != null) { providers.add(TestProxyBeanPostProcessor.this.beanFactory.getBean(bean)); } } } catch (Exception e) { e.printStackTrace(); } String url = TestProxyBeanPostProcessor.this.resolver.resolveStringValue("${server.url:http://localhost:${jaxrs.bindport:${svc.port:8080}}}"); return JAXRSClientFactory.create(url, this.getDependencyDescriptor().getDependencyType(), providers); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableThriftServer.class); for (String name : enablers) { if (context.getBeanFactory().isTypeMatch(name, ThriftServerService.class)) { return ConditionOutcome.match("found @EnableThriftServer on a ThriftServerService"); } } return ConditionOutcome.noMatch("found no @EnableThriftServer on a ThriftServerService"); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] commands = context.getBeanFactory().getBeanNamesForAnnotation(Command.class); ConditionMessage.Builder message = ConditionMessage.forCondition("@Command Condition"); if (commands.length == 0) { return ConditionOutcome.noMatch(message.didNotFind("@Command beans").atAll()); } else { return ConditionOutcome.match(message.found("@Command beans").items((Object[]) commands)); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory() .getBeanNamesForAnnotation(EnableWebSecurity.class); ConditionMessage.Builder message = ConditionMessage .forCondition("@EnableWebSecurity Condition"); if (enablers != null && enablers.length > 0) { return ConditionOutcome.match(message .found("@EnableWebSecurity annotation on Application") .items(enablers)); } return ConditionOutcome.noMatch(message.didNotFind( "@EnableWebSecurity annotation " + "on Application") .atAll()); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory() .getBeanNamesForAnnotation(EnableResourceServer.class); ConditionMessage.Builder message = ConditionMessage .forCondition("@EnableResourceServer Condition"); if (enablers != null && enablers.length > 0) { return ConditionOutcome.match(message .found("@EnableResourceServer annotation on Application") .items(enablers)); } return ConditionOutcome.noMatch(message.didNotFind( "@EnableResourceServer annotation " + "on Application") .atAll()); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory() .getBeanNamesForAnnotation(EnableOAuth2Sso.class); ConditionMessage.Builder message = ConditionMessage .forCondition("@EnableOAuth2Sso Condition"); for (String name : enablers) { if (context.getBeanFactory().isTypeMatch(name, WebSecurityConfigurerAdapter.class)) { return ConditionOutcome.match(message .found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter") .items(name)); } } return ConditionOutcome.noMatch(message.didNotFind( "@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter") .atAll()); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory() .getBeanNamesForAnnotation(EnableOAuth2Sso.class); ConditionMessage.Builder message = ConditionMessage .forCondition("@EnableOAuth2Sso Condition"); for (String name : enablers) { if (context.getBeanFactory().isTypeMatch(name, WebSecurityConfigurerAdapter.class)) { return ConditionOutcome.match(message.found( "@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter") .items(name)); } } return ConditionOutcome.noMatch(message.didNotFind( "@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter") .atAll()); }