本文整理汇总了Java中org.springframework.beans.factory.support.RootBeanDefinition.setFactoryMethodName方法的典型用法代码示例。如果您正苦于以下问题:Java RootBeanDefinition.setFactoryMethodName方法的具体用法?Java RootBeanDefinition.setFactoryMethodName怎么用?Java RootBeanDefinition.setFactoryMethodName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.factory.support.RootBeanDefinition
的用法示例。
在下文中一共展示了RootBeanDefinition.setFactoryMethodName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeMethodTrigger
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
public static BeanFactory makeMethodTrigger ( Object o, String method ) throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition caller = new RootBeanDefinition();
caller.setFactoryBeanName("obj");
caller.setFactoryMethodName(method);
Reflections.setFieldValue(caller.getMethodOverrides(), "overrides", new HashSet<>());
bf.registerBeanDefinition("caller", caller);
Reflections.getField(DefaultListableBeanFactory.class, "beanClassLoader").set(bf, null);
Reflections.getField(DefaultListableBeanFactory.class, "alreadyCreated").set(bf, new HashSet<>());
Reflections.getField(DefaultListableBeanFactory.class, "singletonsCurrentlyInCreation").set(bf, new HashSet<>());
Reflections.getField(DefaultListableBeanFactory.class, "inCreationCheckExclusions").set(bf, new HashSet<>());
Reflections.getField(DefaultListableBeanFactory.class, "logger").set(bf, new NoOpLog());
Reflections.getField(DefaultListableBeanFactory.class, "prototypesCurrentlyInCreation").set(bf, new ThreadLocal<>());
@SuppressWarnings ( "unchecked" )
Map<String, Object> objs = (Map<String, Object>) Reflections.getFieldValue(bf, "singletonObjects");
objs.put("obj", o);
return bf;
}
示例2: testGenericsBasedInjectionIntoMatchingTypeVariable
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testGenericsBasedInjectionIntoMatchingTypeVariable() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class);
bd.setFactoryMethodName("create");
bf.registerBeanDefinition("bean1", bd);
bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class));
GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1");
GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2");
assertSame(bean2, bean1.gi2);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AutowiredAnnotationBeanPostProcessorTests.java
示例3: testGenericsBasedInjectionIntoTypeVariableSelectingBestMatchAgainstFactoryMethodSignature
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
@Ignore // SPR-11521
public void testGenericsBasedInjectionIntoTypeVariableSelectingBestMatchAgainstFactoryMethodSignature() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class);
bd.setFactoryMethodName("createErased");
bf.registerBeanDefinition("bean1", bd);
bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class));
bf.registerBeanDefinition("bean2a", new RootBeanDefinition(ReallyGenericInterface2Impl.class));
bf.registerBeanDefinition("bean2b", new RootBeanDefinition(PlainGenericInterface2Impl.class));
GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1");
GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2");
assertSame(bean2, bean1.gi2);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AutowiredAnnotationBeanPostProcessorTests.java
示例4: testStaticFactoryMethodFoundByNonEagerTypeMatching
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testStaticFactoryMethodFoundByNonEagerTypeMatching() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBeanFactory.class);
rbd.setFactoryMethodName("createTestBean");
lbf.registerBeanDefinition("x1", rbd);
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertEquals(1, beanNames.length);
assertEquals("x1", beanNames[0]);
assertFalse(lbf.containsSingleton("x1"));
assertTrue(lbf.containsBean("x1"));
assertFalse(lbf.containsBean("&x1"));
assertTrue(lbf.isSingleton("x1"));
assertFalse(lbf.isSingleton("&x1"));
assertFalse(lbf.isPrototype("x1"));
assertFalse(lbf.isPrototype("&x1"));
assertTrue(lbf.isTypeMatch("x1", TestBean.class));
assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
assertEquals(TestBean.class, lbf.getType("x1"));
assertEquals(null, lbf.getType("&x1"));
assertFalse(TestBeanFactory.initialized);
}
示例5: testStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBeanFactory.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.setFactoryMethodName("createTestBean");
lbf.registerBeanDefinition("x1", rbd);
TestBeanFactory.initialized = false;
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertEquals(1, beanNames.length);
assertEquals("x1", beanNames[0]);
assertFalse(lbf.containsSingleton("x1"));
assertTrue(lbf.containsBean("x1"));
assertFalse(lbf.containsBean("&x1"));
assertFalse(lbf.isSingleton("x1"));
assertFalse(lbf.isSingleton("&x1"));
assertTrue(lbf.isPrototype("x1"));
assertFalse(lbf.isPrototype("&x1"));
assertTrue(lbf.isTypeMatch("x1", TestBean.class));
assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
assertEquals(TestBean.class, lbf.getType("x1"));
assertEquals(null, lbf.getType("&x1"));
assertFalse(TestBeanFactory.initialized);
}
示例6: testPrototypeWithArrayConversionForFactoryMethod
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testPrototypeWithArrayConversionForFactoryMethod() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
List<String> list = new ManagedList<String>();
list.add("myName");
list.add("myBeanName");
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bd.setFactoryMethodName("create");
bd.getConstructorArgumentValues().addGenericArgumentValue(list);
lbf.registerBeanDefinition("test", bd);
DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
assertEquals("myName", tb.getName());
assertEquals("myBeanName", tb.getBeanName());
DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
assertTrue(tb != tb2);
assertEquals("myName", tb2.getName());
assertEquals("myBeanName", tb2.getBeanName());
}
示例7: registerTransactionAspect
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
private void registerTransactionAspect(Element element, ParserContext parserContext) {
String txAspectBeanName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME;
String txAspectClassName = TransactionManagementConfigUtils.TRANSACTION_ASPECT_CLASS_NAME;
if (!parserContext.getRegistry().containsBeanDefinition(txAspectBeanName)) {
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(txAspectClassName);
def.setFactoryMethodName("aspectOf");
registerTransactionManager(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, txAspectBeanName));
}
}
示例8: parse
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf");
def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
def.setSource(parserContext.extractSource(element));
parserContext.registerBeanComponent(new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME));
}
return null;
}
示例9: registerCacheAspect
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
/**
* Registers a
* <pre class="code">
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
* <property name="cacheManager" ref="cacheManager"/>
* <property name="keyGenerator" ref="keyGenerator"/>
* </bean>
* </pre>
*/
private void registerCacheAspect(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ASPECT_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf");
parseCacheManagerProperty(element, def);
CacheNamespaceHandler.parseKeyGenerator(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME));
}
}
示例10: createBeanDefinition
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
private RootBeanDefinition createBeanDefinition(MockDefinition mockDefinition) {
RootBeanDefinition definition = new RootBeanDefinition(
mockDefinition.getClassToMock());
definition.setTargetType(mockDefinition.getClassToMock());
definition.setFactoryBeanName(BEAN_NAME);
definition.setFactoryMethodName("createMock");
definition.getConstructorArgumentValues().addIndexedArgumentValue(0,
mockDefinition);
return definition;
}
示例11: registerCacheAspect
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
/**
* Registers a
* <pre class="code">
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
* <property name="cacheManager" ref="cacheManager"/>
* <property name="keyGenerator" ref="keyGenerator"/>
* </bean>
* </pre>
*/
private static void registerCacheAspect(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf");
parseCacheResolution(element, def, false);
CacheNamespaceHandler.parseKeyGenerator(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME));
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AnnotationDrivenCacheBeanDefinitionParser.java
示例12: testPostProcessorWithNullBean
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testPostProcessorWithNullBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
RootBeanDefinition rbd = new RootBeanDefinition(NullFactory.class);
rbd.setFactoryMethodName("create");
bf.registerBeanDefinition("bean", rbd);
assertNull(bf.getBean("bean"));
bf.destroySingletons();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:CommonAnnotationBeanPostProcessorTests.java
示例13: testGenericsBasedFieldInjectionWithSimpleMatchAndMockito
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testGenericsBasedFieldInjectionWithSimpleMatchAndMockito() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(RepositoryFieldInjectionBeanWithSimpleMatch.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", bd);
RootBeanDefinition rbd = new RootBeanDefinition();
rbd.setBeanClassName(Mockito.class.getName());
rbd.setFactoryMethodName("mock");
// TypedStringValue used to be equivalent to an XML-defined argument String
rbd.getConstructorArgumentValues().addGenericArgumentValue(new TypedStringValue(Repository.class.getName()));
bf.registerBeanDefinition("repo", rbd);
RepositoryFieldInjectionBeanWithSimpleMatch bean = (RepositoryFieldInjectionBeanWithSimpleMatch) bf.getBean("annotatedBean");
Repository repo = bf.getBean("repo", Repository.class);
assertSame(repo, bean.repository);
assertSame(repo, bean.stringRepository);
assertSame(1, bean.repositoryArray.length);
assertSame(1, bean.stringRepositoryArray.length);
assertSame(repo, bean.repositoryArray[0]);
assertSame(repo, bean.stringRepositoryArray[0]);
assertSame(1, bean.repositoryList.size());
assertSame(1, bean.stringRepositoryList.size());
assertSame(repo, bean.repositoryList.get(0));
assertSame(repo, bean.stringRepositoryList.get(0));
assertSame(1, bean.repositoryMap.size());
assertSame(1, bean.stringRepositoryMap.size());
assertSame(repo, bean.repositoryMap.get("repo"));
assertSame(repo, bean.stringRepositoryMap.get("repo"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:36,代码来源:AutowiredAnnotationBeanPostProcessorTests.java
示例14: registerCacheAspect
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
private static void registerCacheAspect(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) {
Object eleSource = parserContext.extractSource(element);
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf");
BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource);
String sourceName =
parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
def.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
parserContext.registerBeanComponent(new BeanComponentDefinition(sourceDef, sourceName));
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
}
}
示例15: testWithFactoryBean
import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testWithFactoryBean() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
RootBeanDefinition beanDef = new RootBeanDefinition(RequiredTestBean.class);
beanDef.setFactoryBeanName("testBeanFactory");
beanDef.setFactoryMethodName("create");
factory.registerBeanDefinition("testBean", beanDef);
factory.registerBeanDefinition("testBeanFactory", new RootBeanDefinition(RequiredTestBeanFactory.class));
RequiredAnnotationBeanPostProcessor bpp = new RequiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(factory);
factory.addBeanPostProcessor(bpp);
factory.preInstantiateSingletons();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:RequiredAnnotationBeanPostProcessorTests.java