Search in sources :

Example 46 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateWithMultipleCandidatesDescriptor.

@Test
public void testAutowireCandidateWithMultipleCandidatesDescriptor() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    lbf.registerBeanDefinition(JUERGEN, person1);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    lbf.registerBeanDefinition(MARK, person2);
    DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0), false);
    assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
    assertTrue(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
Also used : DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) MethodParameter(org.springframework.core.MethodParameter) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Example 47 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project ignite by apache.

the class GridFactorySelfTest method getTestApplicationContext.

/**
 * Gets test Spring application context with single {@link StringBuilder} bean
 * with name "myBean" and value "Test string".
 *
 * @return Spring application context.
 */
private ApplicationContext getTestApplicationContext() {
    AbstractBeanDefinition def = new GenericBeanDefinition();
    def.setBeanClass(StringBuilder.class);
    ConstructorArgumentValues args = new ConstructorArgumentValues();
    args.addGenericArgumentValue("Test string");
    def.setConstructorArgumentValues(args);
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.registerBeanDefinition("myBean", def);
    return ctx;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 48 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParserIntegrationTests method setsUpMongoDbFactoryUsingAMongoClientUri.

// DATAMONGO-1218
@Test
public void setsUpMongoDbFactoryUsingAMongoClientUri() {
    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-client-uri.xml"));
    BeanDefinition definition = factory.getBeanDefinition("mongoDbFactory");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();
    assertThat(constructorArguments.getArgumentCount(), is(1));
    ValueHolder argument = constructorArguments.getArgumentValue(0, MongoClientURI.class);
    assertThat(argument, is(notNullValue()));
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) ClassPathResource(org.springframework.core.io.ClassPathResource) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Example 49 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParserIntegrationTests method setsUpUriWithId.

// DATAMONGO-1293
@Test
public void setsUpUriWithId() {
    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-uri-and-id.xml"));
    BeanDefinition definition = factory.getBeanDefinition("testMongo");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();
    assertThat(constructorArguments.getArgumentCount(), is(1));
    ValueHolder argument = constructorArguments.getArgumentValue(0, MongoClientURI.class);
    assertThat(argument, is(notNullValue()));
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) ClassPathResource(org.springframework.core.io.ClassPathResource) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Example 50 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project cxf by apache.

the class BusWiringBeanFactoryPostProcessor method postProcessBeanFactory.

public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
    Object inject = bus;
    if (inject == null) {
        inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true, null);
    } else {
        if (!factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID) && !factory.containsSingleton(Bus.DEFAULT_BUS_ID)) {
            factory.registerSingleton(Bus.DEFAULT_BUS_ID, bus);
        }
    }
    for (String beanName : factory.getBeanDefinitionNames()) {
        BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
        BusWiringType type = (BusWiringType) beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        if (type == null) {
            continue;
        }
        String busname = (String) beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        String create = (String) beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        Object inj = inject;
        if (busname != null) {
            if (bus != null) {
                continue;
            }
            inj = getBusForName(busname, factory, create != null, create);
        }
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        if (create == null) {
            if (BusWiringType.PROPERTY == type) {
                beanDefinition.getPropertyValues().addPropertyValue("bus", inj);
            } else if (BusWiringType.CONSTRUCTOR == type) {
                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
                insertConstructorArg(constructorArgs, inj);
            }
        }
    }
}
Also used : BusWiringType(org.apache.cxf.configuration.spring.BusWiringType) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Aggregations

ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)96 Test (org.junit.Test)63 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)50 BeanCreationException (org.springframework.beans.factory.BeanCreationException)23 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)15 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)14 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)9 ValueHolder (org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)8 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)8 Element (org.w3c.dom.Element)8 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)7 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5 LinkedHashSet (java.util.LinkedHashSet)4 InjectionPoint (org.springframework.beans.factory.InjectionPoint)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 ManagedList (org.springframework.beans.factory.support.ManagedList)4 MethodParameter (org.springframework.core.MethodParameter)4