Search in sources :

Example 26 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project grails-core by grails.

the class DefaultBeanConfiguration method createBeanDefinition.

protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd = new GenericBeanDefinition();
    if (!constructorArgs.isEmpty()) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        bd.setConstructorArgumentValues(cav);
    }
    if (clazz != null) {
        bd.setLazyInit(clazz.getAnnotation(Lazy.class) != null);
        bd.setBeanClass(clazz);
    }
    bd.setScope(singleton ? AbstractBeanDefinition.SCOPE_SINGLETON : AbstractBeanDefinition.SCOPE_PROTOTYPE);
    if (parentName != null) {
        bd.setParentName(parentName);
    }
    wrapper = new BeanWrapperImpl(bd);
    return bd;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 27 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project qi4j-sdk by Qi4j.

the class Qi4jBootstrapBeanDefinitionParser method parse.

@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
    Qi4jApplicationBootstrap bootstrap = createQi4jApplicationBootstrap(anElement, aParserContext);
    AbstractBeanDefinition factoryBeanDefinition = createQi4jApplicationFactoryBeanDefinition(bootstrap);
    registerBean(aParserContext, factoryBeanDefinition);
    return factoryBeanDefinition;
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Qi4jApplicationBootstrap(org.qi4j.library.spring.bootstrap.Qi4jApplicationBootstrap)

Example 28 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project qi4j-sdk by Qi4j.

the class Qi4jServiceBeanDefinitionParser method parse.

@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
    String serviceId = anElement.getAttribute(SERVICE_ID);
    // Service factory bean
    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceFactoryBean.class);
    builder.addConstructorArgReference(BEAN_ID_QI4J_APPLICATION);
    builder.addConstructorArgValue(serviceId);
    AbstractBeanDefinition definition = builder.getBeanDefinition();
    // Register service factory bean
    BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry();
    definitionRegistry.registerBeanDefinition(serviceId, definition);
    return definition;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 29 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-security by spring-projects.

the class AbstractUserDetailsServiceBeanDefinitionParser method resolveId.

private String resolveId(Element element, AbstractBeanDefinition definition, ParserContext pc) throws BeanDefinitionStoreException {
    String id = element.getAttribute("id");
    if (pc.isNested()) {
        // We're inside an <authentication-provider> element
        if (!StringUtils.hasText(id)) {
            id = pc.getReaderContext().generateBeanName(definition);
        }
        BeanDefinition container = pc.getContainingBeanDefinition();
        container.getPropertyValues().add("userDetailsService", new RuntimeBeanReference(id));
    }
    if (StringUtils.hasText(id)) {
        return id;
    }
    // If top level, use the default name or throw an exception if already used
    if (pc.getRegistry().containsBeanDefinition(BeanIds.USER_DETAILS_SERVICE)) {
        throw new BeanDefinitionStoreException("No id supplied and another " + "bean is already registered as " + BeanIds.USER_DETAILS_SERVICE);
    }
    return BeanIds.USER_DETAILS_SERVICE;
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 30 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method twoPlacholderConfigurers_withConflictingSettings.

/**
	 * Creates a scenario in which two PPCs are configured, each with different
	 * settings regarding resolving properties from the environment.
	 */
@Test
public void twoPlacholderConfigurers_withConflictingSettings() {
    String P2 = "p2";
    String P2_LOCAL_PROPS_VAL = "p2LocalPropsVal";
    String P2_SYSTEM_PROPS_VAL = "p2SystemPropsVal";
    String P2_SYSTEM_ENV_VAL = "p2SystemEnvVal";
    AbstractBeanDefinition p2BeanDef = rootBeanDefinition(TestBean.class).addPropertyValue("name", "${" + P1 + "}").addPropertyValue("country", "${" + P2 + "}").getBeanDefinition();
    bf.registerBeanDefinition("p1Bean", p1BeanDef);
    bf.registerBeanDefinition("p2Bean", p2BeanDef);
    ppc.setIgnoreUnresolvablePlaceholders(true);
    ppc.postProcessBeanFactory(bf);
    System.setProperty(P2, P2_SYSTEM_PROPS_VAL);
    getModifiableSystemEnvironment().put(P2, P2_SYSTEM_ENV_VAL);
    Properties ppc2Properties = new Properties();
    ppc2Properties.put(P2, P2_LOCAL_PROPS_VAL);
    PropertyPlaceholderConfigurer ppc2 = new PropertyPlaceholderConfigurer();
    ppc2.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    ppc2.setProperties(ppc2Properties);
    ppc2Properties = new Properties();
    ppc2Properties.setProperty(P2, P2_LOCAL_PROPS_VAL);
    ppc2.postProcessBeanFactory(bf);
    TestBean p1Bean = bf.getBean("p1Bean", TestBean.class);
    assertThat(p1Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
    TestBean p2Bean = bf.getBean("p2Bean", TestBean.class);
    assertThat(p2Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
    assertThat(p2Bean.getCountry(), equalTo(P2_SYSTEM_PROPS_VAL));
    System.clearProperty(P2);
    getModifiableSystemEnvironment().remove(P2);
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) TestBean(org.springframework.tests.sample.beans.TestBean) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)44 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)13 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)13 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)7 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)4 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)4 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)3 ArrayList (java.util.ArrayList)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)2 ChildBeanDefinition (org.springframework.beans.factory.support.ChildBeanDefinition)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1