List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory autowireBeanProperties
void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException;
From source file:org.springframework.test.context.support.DependencyInjectionTestExecutionListener.java
/** * Performs dependency injection and bean initialization for the supplied * {@link TestContext} as described in/*from w ww . ja va2 s.c om*/ * {@link #prepareTestInstance(TestContext) prepareTestInstance()}. * <p>The {@link #REINJECT_DEPENDENCIES_ATTRIBUTE} will be subsequently removed * from the test context, regardless of its value. * @param testContext the test context for which dependency injection should * be performed (never {@code null}) * @throws Exception allows any exception to propagate * @see #prepareTestInstance(TestContext) * @see #beforeTestMethod(TestContext) */ protected void injectDependencies(final TestContext testContext) throws Exception { Object bean = testContext.getTestInstance(); AutowireCapableBeanFactory beanFactory = testContext.getApplicationContext() .getAutowireCapableBeanFactory(); beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false); beanFactory.initializeBean(bean, testContext.getTestClass().getName()); testContext.removeAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE); }
From source file:org.usergrid.tools.ToolBase.java
public void startSpring() { // copy("/testApplicationContext.xml", TMP); String[] locations = { "toolsApplicationContext.xml" }; ApplicationContext ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "testClient"); assertNotNull(emf);// www .ja va 2s . co m assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); }