當前位置: 首頁>>代碼示例>>Java>>正文


Java Import類代碼示例

本文整理匯總了Java中org.springframework.context.annotation.Import的典型用法代碼示例。如果您正苦於以下問題:Java Import類的具體用法?Java Import怎麽用?Java Import使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Import類屬於org.springframework.context.annotation包,在下文中一共展示了Import類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConfigurationImportsFor

import org.springframework.context.annotation.Import; //導入依賴的package包/類
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;
}
 
開發者ID:jillesvangurp,項目名稱:spring-depend,代碼行數:21,代碼來源:SpringDependencyAnalyzer.java

示例2: create

import org.springframework.context.annotation.Import; //導入依賴的package包/類
public PolicyContextProvider create(PolicyContext policyContext) {
    Import importAnnotation = policyContext.getClass().getAnnotation(Import.class);

    List<Class<?>> importClasses = Arrays.asList(importAnnotation.value());

    LOGGER.info("Initializing a Spring context provider from @Import annotation: {}",
            String.join(",",
                    importClasses
                            .stream()
                            .map(Class::getName)
                            .collect(Collectors.toSet())));

    AnnotationConfigApplicationContext policyApplicationContext = new AnnotationConfigApplicationContext();
    policyApplicationContext.setClassLoader(policyContext.getClass().getClassLoader());
    importClasses.forEach(policyApplicationContext::register);

    // TODO: set the parent application context ?
    // pluginContext.setEnvironment(applicationContextParent.getEnvironment());
    // pluginContext.setParent(applicationContextParent);

    policyApplicationContext.refresh();
    return new SpringPolicyContextProvider(policyApplicationContext);
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:24,代碼來源:SpringPolicyContextProviderFactory.java

示例3: getConfigImports

import org.springframework.context.annotation.Import; //導入依賴的package包/類
/**
 * 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<>();
}
 
開發者ID:christophd,項目名稱:citrus-admin,代碼行數:14,代碼來源:SpringJavaConfigService.java

示例4: createContextCustomizer

import org.springframework.context.annotation.Import; //導入依賴的package包/類
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
		List<ContextConfigurationAttributes> configAttributes) {
	if (AnnotatedElementUtils.findMergedAnnotation(testClass, Import.class) != null) {
		assertHasNoBeanMethods(testClass);
		return new ImportsContextCustomizer(testClass);
	}
	return null;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:ImportsContextCustomizerFactory.java

示例5: getCompleteConfiguration

import org.springframework.context.annotation.Import; //導入依賴的package包/類
/**
 * 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.
 */
public static Class<?>[] getCompleteConfiguration() {
	List<Class<?>> configClasses = new ArrayList<>();
	configClasses.add(SpringIntegrationBinderConfiguration.class);
	Import annotation = AnnotationUtils.getAnnotation(EnableBinding.class, Import.class);
	Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation);
	configClasses.addAll(Arrays.asList((Class<?>[])annotationAttributes.get("value")));
	return configClasses.toArray(new Class<?>[] {});
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream,代碼行數:16,代碼來源:SpringIntegrationBinderConfiguration.java

示例6: create0

import org.springframework.context.annotation.Import; //導入依賴的package包/類
private <T> T create0(Plugin plugin, Class<T> certificateClass, CertificateConfiguration certificateConfiguration) {
    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));

                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;
    }
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:42,代碼來源:CertificatePluginManagerImpl.java

示例7: create0

import org.springframework.context.annotation.Import; //導入依賴的package包/類
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;
    }
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:46,代碼來源:ExtensionGrantPluginManagerImpl.java

示例8: create0

import org.springframework.context.annotation.Import; //導入依賴的package包/類
private <T> T create0(Plugin plugin, Class<T> identityClass, IdentityProviderConfiguration identityProviderConfiguration,
                      IdentityProviderMapper identityProviderMapper, IdentityProviderRoleMapper identityProviderRoleMapper) {
    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 identity provider configuration bean
                configurableApplicationContext.addBeanFactoryPostProcessor(
                        new IdentityProviderConfigurationBeanFactoryPostProcessor(identityProviderConfiguration));

                // Add identity provider mapper bean
                configurableApplicationContext.addBeanFactoryPostProcessor(
                        new IdentityProviderMapperBeanFactoryPostProcessor(identityProviderMapper));

                // Add identity provider role mapper bean
                configurableApplicationContext.addBeanFactoryPostProcessor(
                        new IdentityProviderRoleMapperBeanFactoryPostProcessor(identityProviderRoleMapper));

                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;
    }
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:51,代碼來源:IdentityProviderPluginManagerImpl.java

示例9: create

import org.springframework.context.annotation.Import; //導入依賴的package包/類
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 MapPropertySource(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;
    }
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:42,代碼來源:IdentityProviderManagerImpl.java

示例10: canHandle

import org.springframework.context.annotation.Import; //導入依賴的package包/類
@Override
public boolean canHandle(PolicyContext policyContext) {
    return policyContext.getClass().getAnnotation(Import.class) != null;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:5,代碼來源:SpringPolicyContextProviderFactory.java


注:本文中的org.springframework.context.annotation.Import類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。