java类org.springframework.beans.factory.config.ConstructorArgumentValues的实例源码

ConfigBeanConfigUtils.java 文件源码 项目:configx 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 修改配置Bean定义,使用静态方法{@link ConfigBeanFactory#FACTORY_METHOD}来实例化。
 *
 * @param registry
 * @param beanName
 * @param beanDefinition
 * @param propertyName
 * @param converterType
 */
public static void setConfigBeanFactoryMethod(BeanDefinitionRegistry registry,
                                              String beanName, BeanDefinition beanDefinition,
                                              String propertyName, Class<?> converterType) {

    // 注册ConfigBeanPropertyResolver
    registerConfigBeanPropertyResolver(registry);

    // 注册ConfigBeanConversionService
    registerConfigBeanConversionService(registry);

    String beanClassName = beanDefinition.getBeanClassName();

    beanDefinition.setBeanClassName(ConfigBeanFactory.class.getName());
    beanDefinition.setFactoryMethodName(ConfigBeanFactory.FACTORY_METHOD);
    ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
    constructorArgumentValues.addGenericArgumentValue(propertyName, String.class.getName());
    constructorArgumentValues.addGenericArgumentValue(beanClassName, Class.class.getName());
    constructorArgumentValues.addGenericArgumentValue(converterType);
    constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(CONFIG_BEAN_PROPERTY_RESOLVER_BEAN_NAME));
    constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(CONFIG_BEAN_CONVERSION_SERVICE_BEAN_NAME));
    beanDefinition.getConstructorArgumentValues().addArgumentValues(constructorArgumentValues);
}
TarantoolRepositoryConfigurationExtension.java 文件源码 项目:spring-data-tarantool 阅读 17 收藏 0 点赞 0 评论 0
@Override
protected AbstractBeanDefinition getDefaultKeyValueTemplateBeanDefinition(
        RepositoryConfigurationSource configurationSource) {
    RootBeanDefinition keyValueTemplateDefinition = new RootBeanDefinition(TarantoolKeyValueTemplate.class);

    ConstructorArgumentValues constructorArgumentValuesForKeyValueTemplate = new ConstructorArgumentValues();
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(0,
            new RuntimeBeanReference(TARANTOOL_OPS_IMPL_BEAN_NAME));
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(1,
            new RuntimeBeanReference(MAPPING_CONTEXT_BEAN_NAME));
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(2,
            new RuntimeBeanReference(TARANTOOL_CONVERTER_BEAN_NAME));

    keyValueTemplateDefinition.setConstructorArgumentValues(constructorArgumentValuesForKeyValueTemplate);

    return keyValueTemplateDefinition;
}
MetadataUtils.java 文件源码 项目:gemini.blueprint 阅读 22 收藏 0 点赞 0 评论 0
static List<BeanArgument> getBeanArguments(BeanDefinition definition) {
    List<BeanArgument> temp;

    ConstructorArgumentValues ctorValues = definition.getConstructorArgumentValues();

    // get indexed values
    Map<Integer, ValueHolder> indexedArguments = ctorValues.getIndexedArgumentValues();

    // check first the indexed arguments
    if (!indexedArguments.isEmpty()) {
        temp = new ArrayList<BeanArgument>(indexedArguments.size());

        for (Map.Entry<Integer, ValueHolder> entry : indexedArguments.entrySet()) {
            temp.add(new SimpleBeanArgument(entry.getKey(), entry.getValue()));
        }
    } else {
        // followed by the generic arguments
        List<ValueHolder> args = ctorValues.getGenericArgumentValues();
        temp = new ArrayList<BeanArgument>(args.size());
        for (ValueHolder valueHolder : args) {
            temp.add(new SimpleBeanArgument(valueHolder));
        }
    }

    return Collections.unmodifiableList(temp);
}
CycleOrderingProcessor.java 文件源码 项目:gemini.blueprint 阅读 19 收藏 0 点赞 0 评论 0
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

        boolean trace = log.isTraceEnabled();

        String[] names = beanFactory.getBeanDefinitionNames();
        for (String name : names) {
            BeanDefinition definition = beanFactory.getBeanDefinition(name);
            if (definition.hasAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME)) {
                ConstructorArgumentValues cArgs = definition.getConstructorArgumentValues();
                if (trace)
                    log.trace("Inspecting cycles for (blueprint) bean " + name);

                tag(cArgs.getGenericArgumentValues(), name, definition);
                tag(cArgs.getIndexedArgumentValues().values(), name, definition);
            }
        }
    }
GroovyBeanDefinitionWrapper.java 文件源码 项目:lams 阅读 23 收藏 0 点赞 0 评论 0
protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(this.clazz);
    if (!CollectionUtils.isEmpty(this.constructorArgs)) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : this.constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        bd.setConstructorArgumentValues(cav);
    }
    if (this.parentName != null) {
        bd.setParentName(this.parentName);
    }
    this.definitionWrapper = new BeanWrapperImpl(bd);
    return bd;
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldWithSingleNonQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e instanceof UnsatisfiedDependencyException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedMethodParameterTestBean bean =
            (QualifiedMethodParameterTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
    context.registerBeanDefinition(JUERGEN,
            ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(person, JUERGEN), context, true).getBeanDefinition());
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedMethodParameterTestBean bean =
            (QualifiedMethodParameterTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(DefaultValueQualifiedPerson.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedMethodParameterTestBean bean =
            (QualifiedMethodParameterTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedConstructorArgumentTestBean bean =
            (QualifiedConstructorArgumentTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldWithMultipleNonQualifiedCandidates() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e instanceof UnsatisfiedDependencyException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesMetaQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(MetaQualifiedFieldTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    MetaQualifiedFieldTestBean bean = (MetaQualifiedFieldTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 17 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredConstructorArgumentResolvesQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedConstructorArgumentTestBean bean =
            (QualifiedConstructorArgumentTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    // qualifier added, but includes no value
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldWithDefaultValueTestBean bean =
            (QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    // qualifier added, and non-default value specified
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class, "not the default"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    // qualifier added, and value matches the default
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class, "default"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldWithDefaultValueTestBean bean =
            (QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesWithMultipleQualifierValues() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
    qualifier.setAttribute("number", 456);
    person1.addQualifier(qualifier);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    AutowireCandidateQualifier qualifier2 = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
    qualifier2.setAttribute("number", 123);
    person2.addQualifier(qualifier2);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldWithMultipleAttributesTestBean bean =
            (QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
    assertEquals(MARK, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
    qualifier.setAttribute("number", 456);
    person1.addQualifier(qualifier);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    AutowireCandidateQualifier qualifier2 = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
    qualifier2.setAttribute("number", 123);
    qualifier2.setAttribute("value", "default");
    person2.addQualifier(qualifier2);
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldWithMultipleAttributesTestBean bean =
            (QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
    assertEquals(MARK, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class));
    context.registerBeanDefinition(JUERGEN, person1);
    context.registerBeanDefinition(MARK, person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldWithBaseQualifierDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedFieldWithBaseQualifierDefaultValueTestBean bean =
            (QualifiedFieldWithBaseQualifierDefaultValueTestBean) context.getBean("autowired");
    assertEquals(MARK, bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 32 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue("the real juergen");
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue("juergen imposter");
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "not really juergen"));
    context.registerBeanDefinition("juergen1", person1);
    context.registerBeanDefinition("juergen2", person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean bean =
            (QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean) context.getBean("autowired");
    assertEquals("the real juergen", bean.getPerson().getName());
}
QualifierAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue("the real juergen");
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue("juergen imposter");
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
    context.registerBeanDefinition("juergen1", person1);
    context.registerBeanDefinition("juergen2", person2);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e instanceof UnsatisfiedDependencyException);
        assertEquals("autowired", e.getBeanName());
    }
}
InjectAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredFieldWithSingleNonQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedFieldTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
InjectAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    try {
        context.refresh();
        fail("expected BeanCreationException");
    }
    catch (BeanCreationException e) {
        assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
        assertEquals("autowired", e.getBeanName());
    }
}
InjectAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    context.registerBeanDefinition(JUERGEN, person);
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedMethodParameterTestBean bean =
            (QualifiedMethodParameterTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}
InjectAnnotationAutowireContextTests.java 文件源码 项目:spring4-understanding 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
    GenericApplicationContext context = new GenericApplicationContext();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
    context.registerBeanDefinition(JUERGEN,
            ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(person, JUERGEN), context, true).getBeanDefinition());
    context.registerBeanDefinition("autowired",
            new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    QualifiedMethodParameterTestBean bean =
            (QualifiedMethodParameterTestBean) context.getBean("autowired");
    assertEquals(JUERGEN, bean.getPerson().getName());
}


问题


面经


文章

微信
公众号

扫码关注公众号