Spring Framework DefaultListableBeanFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework DefaultListableBeanFactory class.

This code example shows how to use the following methods:getBean, getBean, getType
 
	private static final Resource CONTEXT = qualifiedResource(PropertyPathFactoryBeanTests.class, "context.xml");
 
	@Test
	public void testPropertyPathFactoryBeanWithSingletonResult() { 
		DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
		new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
		assertEquals(new Integer(12), xbf.getBean("propertyPath1"));
		assertEquals(new Integer(11), xbf.getBean("propertyPath2"));
		assertEquals(new Integer(10), xbf.getBean("tb.age"));
		assertEquals(ITestBean.class, xbf.getType("otb.spouse"));
		Object result1 = xbf.getBean("otb.spouse");
		Object result2 = xbf.getBean("otb.spouse");
		assertTrue(result1 instanceof TestBean);
		assertTrue(result1 == result2);
		assertEquals(99, ((TestBean) result1).getAge());
	} 
 
	@Test
	public void testPropertyPathFactoryBeanWithPrototypeResult() { 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBean, registerBeanDefinition, registerSingleton
public class PersistenceExceptionTranslationInterceptorTests extends PersistenceExceptionTranslationAdvisorTests { 
 
	@Override 
	protected void addPersistenceExceptionTranslation(ProxyFactory pf, PersistenceExceptionTranslator pet) { 
		if (AnnotationUtils.findAnnotation(pf.getTargetClass(), Repository.class) != null) { 
			DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 
			bf.registerBeanDefinition("peti", new RootBeanDefinition(PersistenceExceptionTranslationInterceptor.class)); 
			bf.registerSingleton("pet", pet); 
			pf.addAdvice((PersistenceExceptionTranslationInterceptor) bf.getBean("peti")); 
		} 
	} 
 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBean, getBeanDefinitionCount
 
		Statement statement = mock(Statement.class);
		given(statement.executeQuery(sql)).willReturn(resultSet);
		given(connection.createStatement()).willReturn(statement);
 
		DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
		JdbcBeanDefinitionReader reader = new JdbcBeanDefinitionReader(bf);
		reader.setDataSource(dataSource);
		reader.loadBeanDefinitions(sql);
		assertEquals("Incorrect number of bean definitions", 1, bf.getBeanDefinitionCount());
		TestBean tb = (TestBean) bf.getBean("one");
		assertEquals("Age in TestBean was wrong.", 53, tb.getAge());
 
		verify(resultSet).close();
		verify(statement).close();
	} 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBean
	@Test
	public void simpleRef() throws Exception {
		DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
		String name = "simple-ref";
		//		beanFactory.getBean("name-value1", TestBean.class); 
		DummyBean nameValue = beanFactory.getBean(name, DummyBean.class);
		assertEquals(beanFactory.getBean("name"), nameValue.getValue());
	} 
 
	@Test
	public void nameValue() throws Exception {
		DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
		String name = "name-value";
		//		beanFactory.getBean("name-value1", TestBean.class); 
		TestBean nameValue = beanFactory.getBean(name, TestBean.class);
		assertEquals(name, nameValue.getName());
		assertEquals(10, nameValue.getAge());
	} 
 
	@Test

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getRegisteredScope, getRegisteredScopeNames, registerScope
 
	private DefaultListableBeanFactory beanFactory;
 
	@Before 
	public void setUp() { 
		beanFactory = new DefaultListableBeanFactory();
		Scope scope = new NoOpScope() {
			private int index;
			private List<TestBean> objects = new LinkedList<TestBean>(); {
				objects.add(new TestBean());
				objects.add(new TestBean());
			} 
			@Override 
			public Object get(String name, ObjectFactory<?> objectFactory) {
				if (index >= objects.size()) {
					index = 0;
				} 
				return objects.get(index++);
			} 
		}; 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBean
		assertEquals(INITIAL_COUNT + 2, proxied.getCount() ); 
	} 
 
	@Test 
	public void testValidSwaps() { 
		SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1"); 
		SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2"); 
 
		SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable"); 
		assertEquals(target1.getCount(), proxied.getCount() ); 
		proxied.doWork(); 
		assertEquals(INITIAL_COUNT + 1, proxied.getCount() ); 
 
		HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper"); 
		Object old = swapper.swap(target2); 
		assertEquals("Correct old target was returned", target1, old); 
 
		// TODO should be able to make this assertion: need to fix target handling 
		// in AdvisedSupport 
		//assertEquals(target2, ((Advised) proxied).getTarget()); 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBean
		} 
 
		// Validate values 
		RabbitAdmin admin;
		if (StringUtils.hasText(adminBeanName)) {
			admin = beanFactory.getBean(adminBeanName, RabbitAdmin.class);
		} else { 
			admin = beanFactory.getBean(RabbitAdmin.class);
		} 
		assertEquals(expectedAutoStartup, admin.isAutoStartup());
		assertEquals(beanFactory.getBean(ConnectionFactory.class), admin.getRabbitTemplate().getConnectionFactory());
 
		if (initialisedWithTemplate) {
			assertEquals(beanFactory.getBean(RabbitTemplate.class), admin.getRabbitTemplate());
		} 
 
	} 
 
	/** 
	 * Load application context. Fail if tests expects invalid spring-context, but spring-context is valid. 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerBeanDefinition
	public void configurationClassesMayNotBeFinal() { 
		@Configuration 
		final class Config { } 
 
		BeanDefinition configBeanDef = rootBeanDefinition(Config.class).getBeanDefinition();
		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
		beanFactory.registerBeanDefinition("config", configBeanDef);
 
		try { 
			ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
			pp.postProcessBeanFactory(beanFactory);
			fail("expected exception"); 
		} 
		catch (BeanDefinitionParsingException ex) {
			assertTrue(ex.getMessage(), ex.getMessage().contains("Remove the final modifier"));
		} 
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerSingleton
		assertNotNull(stepLocator.getStep("foo"));
	} 
 
	@Test
	public void testGetStepNames() throws Exception {
		beanFactory.registerSingleton("foo", new StubStep("foo"));
		beanFactory.registerSingleton("bar", new StubStep("bar"));
		stepLocator.setBeanFactory(beanFactory);
		assertEquals(2, stepLocator.getStepNames().size());
	} 
 
	private static final class StubStep implements Step { 
 
		private String name;
		 
		public StubStep(String name) {
			this.name = name;
		} 
 
		public void execute(StepExecution stepExecution) throws JobInterruptedException {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerSingleton
 */ 
public class GenericApplicationContextTests { 
 
	@Test
	public void nullBeanRegistration() { 
		DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
		bf.registerSingleton("nullBean", null);
		new GenericApplicationContext(bf).refresh();
	} 
 
	@Test
	public void getBeanForClass() { 
		GenericApplicationContext ac = new GenericApplicationContext();
		ac.registerBeanDefinition("testBean", new RootBeanDefinition(String.class));
		ac.refresh();
 
		assertSame(ac.getBean("testBean"), ac.getBean(String.class));
		assertSame(ac.getBean("testBean"), ac.getBean(CharSequence.class));
 
		try { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework DefaultListableBeanFactory Methods: