Search in sources :

Example 21 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-connectors by spring-cloud.

the class AbstractCloudServiceConnectorFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();
    if (cloud == null) {
        if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
            beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
        }
        CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
        cloud = cloudFactory.getCloud();
    }
    if (!StringUtils.hasText(serviceId)) {
        List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
        if (infos.size() != 1) {
            throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found " + infos.size());
        }
        serviceId = infos.get(0).getId();
    }
    super.afterPropertiesSet();
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) CloudException(org.springframework.cloud.CloudException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 22 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class OnExpressionCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String expression = (String) metadata.getAnnotationAttributes(ConditionalOnExpression.class.getName()).get("value");
    expression = wrapIfNecessary(expression);
    String rawExpression = expression;
    expression = context.getEnvironment().resolvePlaceholders(expression);
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    BeanExpressionResolver resolver = (beanFactory != null) ? beanFactory.getBeanExpressionResolver() : null;
    BeanExpressionContext expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, null) : null;
    if (resolver == null) {
        resolver = new StandardBeanExpressionResolver();
    }
    boolean result = (Boolean) resolver.evaluate(expression, expressionContext);
    return new ConditionOutcome(result, ConditionMessage.forCondition(ConditionalOnExpression.class, "(" + rawExpression + ")").resultedIn(result));
}
Also used : StandardBeanExpressionResolver(org.springframework.context.expression.StandardBeanExpressionResolver) BeanExpressionResolver(org.springframework.beans.factory.config.BeanExpressionResolver) StandardBeanExpressionResolver(org.springframework.context.expression.StandardBeanExpressionResolver) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanExpressionContext(org.springframework.beans.factory.config.BeanExpressionContext)

Example 23 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class ServletWebServerApplicationContext method selfInitialize.

private void selfInitialize(ServletContext servletContext) throws ServletException {
    prepareWebApplicationContext(servletContext);
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(beanFactory);
    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, getServletContext());
    existingScopes.restore();
    WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, getServletContext());
    for (ServletContextInitializer beans : getServletContextInitializerBeans()) {
        beans.onStartup(servletContext);
    }
}
Also used : ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ServletContextInitializer(org.springframework.boot.web.servlet.ServletContextInitializer)

Example 24 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-connectors by spring-cloud.

the class CloudScanHelper method initializeCloud.

private void initializeCloud(BeanDefinitionRegistry registry) {
    if (cloud != null) {
        return;
    }
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;
    if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
        beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
    }
    CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
    cloud = cloudFactory.getCloud();
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 25 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method doesNotReplaceExistingScopes.

@Test
public void doesNotReplaceExistingScopes() throws Exception {
    // gh-2082
    Scope scope = mock(Scope.class);
    ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
    factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope);
    factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope);
    addWebServerFactoryBean();
    this.context.refresh();
    assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST)).isSameAs(scope);
    assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_SESSION)).isSameAs(scope);
}
Also used : SessionScope(org.springframework.web.context.request.SessionScope) Scope(org.springframework.beans.factory.config.Scope) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)32 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 ApplicationContext (org.springframework.context.ApplicationContext)4 Test (org.junit.Test)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)3 CloudFactory (org.springframework.cloud.CloudFactory)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 BeansException (org.springframework.beans.BeansException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)2 GrailsPlugin (grails.plugins.GrailsPlugin)1 ConfigObject (groovy.util.ConfigObject)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 ServletContext (javax.servlet.ServletContext)1 MultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProperties)1 NavigableMap (org.grails.config.NavigableMap)1