org.springframework.context.annotation.Import Java Examples
The following examples show how to use
org.springframework.context.annotation.Import.
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: SpringDependencyAnalyzer.java From spring-depend with MIT License | 6 votes |
private static List<Class<?>> getConfigurationImportsFor(Class<?> clazz) { List<Class<?>> list = new ArrayList<>(); for (Annotation annotation : clazz.getAnnotations()) { Class<? extends Annotation> type = annotation.annotationType(); if (Import.class.equals(type)) { try { Method method = type.getMethod("value"); Class<?>[] imports = (Class<?>[]) method.invoke(annotation, (Object[]) null); if (imports != null && imports.length > 0) { for (Class<?> c : imports) { list.add(c); } } } catch (Throwable e) { throw new IllegalStateException(e); } } } return list; }
Example #2
Source File: TestChannelBinderConfiguration.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
/** * Utility operation to return an array of configuration classes defined in * {@link EnableBinding} annotation. Typically used for tests that do not rely on * creating an SCSt boot application annotated with {@link EnableBinding}, yet require * full {@link Binder} configuration. * @param additionalConfigurationClasses config classes to be added to the default * config * @return an array of configuration classes defined in {@link EnableBinding} * annotation */ public static Class<?>[] getCompleteConfiguration( Class<?>... additionalConfigurationClasses) { List<Class<?>> configClasses = new ArrayList<>(); configClasses.add(TestChannelBinderConfiguration.class); Import annotation = AnnotationUtils.getAnnotation(EnableBinding.class, Import.class); Map<String, Object> annotationAttributes = AnnotationUtils .getAnnotationAttributes(annotation); configClasses .addAll(Arrays.asList((Class<?>[]) annotationAttributes.get("value"))); configClasses.add(BindingServiceConfiguration.class); if (additionalConfigurationClasses != null) { configClasses.addAll(Arrays.asList(additionalConfigurationClasses)); } return configClasses.toArray(new Class<?>[] {}); }
Example #3
Source File: TestModuleInitializer.java From spring-init with Apache License 2.0 | 5 votes |
@Override public void initialize(GenericApplicationContext context) { if (!ClassUtils.isPresent("org.springframework.boot.test.context.ImportsContextCustomizer", context.getClassLoader()) || !context.getEnvironment().getProperty("spring.functional.enabled", Boolean.class, true)) { // Only used in tests - could move to separate jar return; } ImportRegistrars registrars; // TODO: extract this logic and share with FunctionalInstallerListener? if (!context.getBeanFactory().containsSingleton(ConditionService.class.getName())) { if (!context.getBeanFactory().containsSingleton(MetadataReaderFactory.class.getName())) { context.getBeanFactory().registerSingleton(MetadataReaderFactory.class.getName(), new CachingMetadataReaderFactory(context.getClassLoader())); } context.getBeanFactory().registerSingleton(ConditionService.class.getName(), new SimpleConditionService(context, context.getBeanFactory(), context.getEnvironment(), context)); registrars = new FunctionalInstallerImportRegistrars(context); context.registerBean(ImportRegistrars.class, () -> registrars); } else { registrars = context.getBean(ImportRegistrars.class.getName(), ImportRegistrars.class); } for (String name : context.getBeanFactory().getBeanDefinitionNames()) { BeanDefinition definition = context.getBeanFactory().getBeanDefinition(name); if (definition.getBeanClassName().contains("ImportsContextCustomizer$ImportsConfiguration")) { SimpleConditionService.EXCLUDES_ENABLED = true; Class<?> testClass = (definition != null) ? (Class<?>) definition.getAttribute("testClass") : null; if (testClass != null) { Set<Import> merged = AnnotatedElementUtils.findAllMergedAnnotations(testClass, Import.class); for (Import ann : merged) { for (Class<?> imported : ann.value()) { registrars.add(testClass, imported); } } } } } }
Example #4
Source File: SpringJavaConfigService.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * Reads file import locations from Spring bean application context. * @param project * @return */ public List<Class<?>> getConfigImports(Class<?> configFile, Project project) { Import importAnnotation = configFile.getAnnotation(Import.class); if (importAnnotation != null) { return Arrays.asList(importAnnotation.value()); } return new ArrayList<>(); }
Example #5
Source File: ExtensionGrantPluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> extensionGrantClass, ExtensionGrantConfiguration extensionGrantConfiguration, AuthenticationProvider authenticationProvider) { if (extensionGrantClass == null) { return null; } try { T extensionGrantObj = createInstance(extensionGrantClass); final Import annImport = extensionGrantClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext extensionGrantApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add extension grant configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new ExtensionGrantConfigurationBeanFactoryPostProcessor(extensionGrantConfiguration)); // Add extension grant identity provider bean configurableApplicationContext.addBeanFactoryPostProcessor( new ExtensionGrantIdentityProviderFactoryPostProcessor(authenticationProvider != null ? authenticationProvider : new NoAuthenticationProvider())); return configurableApplicationContext; } }); extensionGrantApplicationContext.getAutowireCapableBeanFactory().autowireBean(extensionGrantObj); if (extensionGrantObj instanceof InitializingBean) { ((InitializingBean) extensionGrantObj).afterPropertiesSet(); } return extensionGrantObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading extension grant", ex); return null; } }
Example #6
Source File: CertificatePluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> certificateClass, CertificateConfiguration certificateConfiguration, CertificateMetadata metadata) { if (certificateClass == null) { return null; } try { T certificateObj = createInstance(certificateClass); final Import annImport = certificateClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add certificate configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new CertificateConfigurationBeanFactoryPostProcessor(certificateConfiguration)); // Add certificate metadata bean configurableApplicationContext.addBeanFactoryPostProcessor( new CertificateMetadataBeanFactoryPostProcessor(metadata)); return configurableApplicationContext; } }); idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(certificateObj); if (certificateObj instanceof InitializingBean) { ((InitializingBean) certificateObj).afterPropertiesSet(); } return certificateObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading certificate", ex); return null; } }
Example #7
Source File: ReporterPluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> auditReporterClass, ReporterConfiguration reporterConfiguration) { if (auditReporterClass == null) { return null; } try { T auditReporterObj = createInstance(auditReporterClass); final Import annImport = auditReporterClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext reporterApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add reporter configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new ReporterConfigurationBeanFactoryPostProcessor(reporterConfiguration)); return configurableApplicationContext; } }); reporterApplicationContext.getAutowireCapableBeanFactory().autowireBean(auditReporterObj); if (auditReporterObj instanceof InitializingBean) { ((InitializingBean) auditReporterObj).afterPropertiesSet(); } return auditReporterObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading reporter", ex); return null; } }
Example #8
Source File: FactorPluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> identityClass, FactorConfiguration factorConfiguration) { if (identityClass == null) { return null; } try { T identityObj = createInstance(identityClass); final Import annImport = identityClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add authenticator configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new FactorConfigurationBeanFactoryPostProcessor(factorConfiguration)); return configurableApplicationContext; } }); idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj); if (identityObj instanceof InitializingBean) { ((InitializingBean) identityObj).afterPropertiesSet(); } return identityObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading factor", ex); return null; } }
Example #9
Source File: IdentityProviderPluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> identityClass, IdentityProviderConfiguration identityProviderConfiguration, IdentityProviderMapper identityProviderMapper, IdentityProviderRoleMapper identityProviderRoleMapper, CertificateManager certificateManager) { if (identityClass == null) { return null; } try { T identityObj = createInstance(identityClass); final Import annImport = identityClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add gravitee properties configurableApplicationContext.addBeanFactoryPostProcessor( new PropertiesBeanFactoryPostProcessor(properties)); // Add Vert.x instance configurableApplicationContext.addBeanFactoryPostProcessor( new VertxBeanFactoryPostProcessor(vertx)); // Add identity provider configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new IdentityProviderConfigurationBeanFactoryPostProcessor(identityProviderConfiguration)); // Add identity provider mapper bean configurableApplicationContext.addBeanFactoryPostProcessor( new IdentityProviderMapperBeanFactoryPostProcessor(identityProviderMapper != null ? identityProviderMapper : new NoIdentityProviderMapper())); // Add identity provider role mapper bean configurableApplicationContext.addBeanFactoryPostProcessor( new IdentityProviderRoleMapperBeanFactoryPostProcessor(identityProviderRoleMapper != null ? identityProviderRoleMapper : new NoIdentityProviderRoleMapper())); if (certificateManager != null) { // Add certificate manager bean configurableApplicationContext.addBeanFactoryPostProcessor(new CertificateManagerBeanFactoryPostProcessor(certificateManager)); } return configurableApplicationContext; } }); idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj); if (identityObj instanceof InitializingBean) { ((InitializingBean) identityObj).afterPropertiesSet(); } return identityObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading identity provider", ex); return null; } }
Example #10
Source File: IdentityProviderPluginManagerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private <T> T create0(Plugin plugin, Class<T> userProvider, IdentityProviderConfiguration identityProviderConfiguration) { try { T identityObj = createInstance(userProvider); final Import annImport = userProvider.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableApplicationContext applicationContext() { ConfigurableApplicationContext configurableApplicationContext = super.applicationContext(); // Add gravitee properties configurableApplicationContext.addBeanFactoryPostProcessor( new PropertiesBeanFactoryPostProcessor(properties)); // Add Vert.x instance configurableApplicationContext.addBeanFactoryPostProcessor( new VertxBeanFactoryPostProcessor(vertx)); // Add identity provider configuration bean configurableApplicationContext.addBeanFactoryPostProcessor( new IdentityProviderConfigurationBeanFactoryPostProcessor(identityProviderConfiguration)); return configurableApplicationContext; } }); idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj); if (identityObj instanceof InitializingBean) { ((InitializingBean) identityObj).afterPropertiesSet(); } return identityObj; } catch (Exception ex) { logger.error("An unexpected error occurs while loading user provider", ex); return null; } }
Example #11
Source File: IdentityProviderManagerImpl.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
private <T> T create(Plugin plugin, Class<T> identityClass, Map<String, Object> properties) { if (identityClass == null) { return null; } try { T identityObj = createInstance(identityClass); final Import annImport = identityClass.getAnnotation(Import.class); Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet(); ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) { @Override public Set<Class<?>> configurations() { return configurations; } @Override public ConfigurableEnvironment environment() { return new StandardEnvironment() { @Override protected void customizePropertySources(MutablePropertySources propertySources) { propertySources.addFirst(new RelaxedPropertySource(plugin.id(), properties)); super.customizePropertySources(propertySources); } }; } }); idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj); if (identityObj instanceof InitializingBean) { ((InitializingBean) identityObj).afterPropertiesSet(); } return identityObj; } catch (Exception ex) { LOGGER.error("An unexpected error occurs while loading identity provider", ex); return null; } }