本文整理匯總了Java中org.springframework.beans.factory.config.ConstructorArgumentValues.addGenericArgumentValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstructorArgumentValues.addGenericArgumentValue方法的具體用法?Java ConstructorArgumentValues.addGenericArgumentValue怎麽用?Java ConstructorArgumentValues.addGenericArgumentValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.beans.factory.config.ConstructorArgumentValues
的用法示例。
在下文中一共展示了ConstructorArgumentValues.addGenericArgumentValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:QualifierAnnotationAutowireContextTests.java
示例2: setConfigBeanFactoryMethod
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
/**
* 修改配置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);
}
示例3: createBeanDefinition
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
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;
}
示例4: testAutowireCandidateWithFieldDescriptor
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@Ignore
@Test
public void testAutowireCandidateWithFieldDescriptor() 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);
lbf.registerBeanDefinition(MARK, person2);
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(
QualifiedTestBean.class.getDeclaredField("qualified"), false);
DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(
QualifiedTestBean.class.getDeclaredField("nonqualified"), false);
assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
assertTrue(lbf.isAutowireCandidate(MARK, null));
assertTrue(lbf.isAutowireCandidate(MARK, nonqualifiedDescriptor));
assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:QualifierAnnotationAutowireBeanFactoryTests.java
示例5: testAutowiredMethodParameterWithSingleNonQualifiedCandidate
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
}
示例6: registerByteCodeLoadingProxy
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
private void registerByteCodeLoadingProxy(String name, String type, Resource resource,
DefaultListableBeanFactory beanFactory) {
Class<?> proxyClass = null;
if ("supplier".equals(type.toLowerCase())) {
proxyClass = ByteCodeLoadingSupplier.class;
}
else if ("consumer".equals(type.toLowerCase())) {
proxyClass = ByteCodeLoadingConsumer.class;
}
else {
proxyClass = ByteCodeLoadingFunction.class;
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(proxyClass);
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.addGenericArgumentValue(resource);
beanDefinition.setConstructorArgumentValues(args);
beanFactory.registerBeanDefinition(name, beanDefinition);
}
示例7: testAutowiredMethodParameterWithStaticallyQualifiedCandidate
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
示例8: testAutowiredFieldWithMultipleNonQualifiedCandidates
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:QualifierAnnotationAutowireContextTests.java
示例9: testAutowiredMethodParameterWithMultipleNonQualifiedCandidates
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:QualifierAnnotationAutowireContextTests.java
示例10: testAutowiredFieldResolvesQualifiedCandidate
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:QualifierAnnotationAutowireContextTests.java
示例11: testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:QualifierAnnotationAutowireContextTests.java
示例12: testAutowiredFieldResolvesWithBaseQualifierAndDefaultValue
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:QualifierAnnotationAutowireContextTests.java
示例13: testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:QualifierAnnotationAutowireContextTests.java
示例14: testAutowiredFieldWithSingleNonQualifiedCandidate
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
}
示例15: testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition
import org.springframework.beans.factory.config.ConstructorArgumentValues; //導入方法依賴的package包/類
@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());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:QualifierAnnotationAutowireContextTests.java