Search in sources :

Example 76 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class EnvironmentEndpoint method getPropertySources.

private MutablePropertySources getPropertySources() {
    MutablePropertySources sources;
    Environment environment = getEnvironment();
    if (environment != null && environment instanceof ConfigurableEnvironment) {
        sources = ((ConfigurableEnvironment) environment).getPropertySources();
    } else {
        sources = new StandardEnvironment().getPropertySources();
    }
    return sources;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Environment(org.springframework.core.env.Environment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 77 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderManagerImpl method create.

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;
    }
}
Also used : Import(org.springframework.context.annotation.Import) AnnotationBasedPluginContextConfigurer(io.gravitee.plugin.core.internal.AnnotationBasedPluginContextConfigurer) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) InitializingBean(org.springframework.beans.factory.InitializingBean) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 78 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-data-commons by spring-projects.

the class AnnotationRepositoryConfigurationSourceUnitTests method setUp.

@Before
public void setUp() {
    AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
    environment = new StandardEnvironment();
    resourceLoader = new DefaultResourceLoader();
    registry = mock(BeanDefinitionRegistry.class);
    source = new AnnotationRepositoryConfigurationSource(annotationMetadata, EnableRepositories.class, resourceLoader, environment, registry);
}
Also used : StandardAnnotationMetadata(org.springframework.core.type.StandardAnnotationMetadata) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata) StandardAnnotationMetadata(org.springframework.core.type.StandardAnnotationMetadata) StandardEnvironment(org.springframework.core.env.StandardEnvironment) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Example 79 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-data-commons by spring-projects.

the class RepositoryBeanDefinitionRegistrarSupportUnitTests method setUp.

@Before
public void setUp() {
    environment = new StandardEnvironment();
    registrar = new DummyRegistrar();
    registrar.setEnvironment(environment);
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Before(org.junit.Before)

Example 80 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-data-commons by spring-projects.

the class RepositoryConfigurationDelegateUnitTests method registersRepositoryBeanNameAsAttribute.

// DATACMNS-892
@Test
public void registersRepositoryBeanNameAsAttribute() {
    StandardEnvironment environment = new StandardEnvironment();
    GenericApplicationContext context = new GenericApplicationContext();
    RepositoryConfigurationSource configSource = new AnnotationRepositoryConfigurationSource(new StandardAnnotationMetadata(TestConfig.class, true), EnableRepositories.class, context, environment, context.getDefaultListableBeanFactory());
    RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, context, environment);
    for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(context, extension)) {
        BeanDefinition beanDefinition = definition.getBeanDefinition();
        assertThat(beanDefinition.getAttribute(RepositoryConfigurationDelegate.FACTORY_BEAN_OBJECT_TYPE).toString(), endsWith("Repository"));
    }
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StandardAnnotationMetadata(org.springframework.core.type.StandardAnnotationMetadata) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)146 Test (org.junit.jupiter.api.Test)63 MapPropertySource (org.springframework.core.env.MapPropertySource)52 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)42 Test (org.junit.Test)39 HashMap (java.util.HashMap)37 URI (java.net.URI)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 MutablePropertySources (org.springframework.core.env.MutablePropertySources)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9