List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory initializeBean
Object initializeBean(Object existingBean, String beanName) throws BeansException;
From source file:gDao.util.SimpleDaoTestInjectHandler.java
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.websocket.WebSocketServer.java
public void startSpring() { String[] locations = getApplicationContextLocations(); ApplicationContext ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "webSocketServer"); assertNotNull(emf);//w w w.j a va2 s . c om assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); }
From source file:org.usergrid.persistence.cassandra.PersistenceTestHelperImpl.java
@Override public void setup() throws Exception { // assertNotNull(client); String maven_opts = System.getenv("MAVEN_OPTS"); logger.info("Maven options: " + maven_opts); logger.info("Starting Cassandra"); embedded = new EmbeddedServerHelper(); embedded.setup();//w w w . j a va2s . c o m // copy("/testApplicationContext.xml", TMP); String[] locations = { "testApplicationContext.xml" }; ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "testClient"); assertNotNull(emf); assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); Setup setup = ((EntityManagerFactoryImpl) emf).getSetup(); logger.info("Setting up Usergrid schema"); setup.setup(); logger.info("Usergrid schema setup"); setup.checkKeyspaces(); }
From source file:org.usergrid.management.cassandra.ManagementTestHelperImpl.java
@Override public void setup() throws Exception { // assertNotNull(client); String maven_opts = System.getenv("MAVEN_OPTS"); logger.info("Maven options: " + maven_opts); logger.info("Starting Cassandra"); embedded = new EmbeddedServerHelper(); embedded.setup();/*from w w w . ja v a 2 s . c o m*/ // copy("/testApplicationContext.xml", TMP); String[] locations = { "testApplicationContext.xml" }; ApplicationContext ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "testClient"); assertNotNull(emf); assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); emf.setup(); management.setup(); }
From source file:com.qpark.eip.core.spring.lockedoperation.AbstractAsyncLockableOperation.java
/** * Invoke the real logic of the {@link LockableOperation}. * * @param context/*w w w . j a v a 2 s .c om*/ * the {@link LockableOperationContext} (could be * <code>null</code>) to pass to the {@link LockableOperation}. */ @Override protected final void invokeOperation(final LockableOperationContext context) { this.getLogger().debug("Create AsyncRunner for the operation {} ({})", new Object[] { this.getName(), this.getUUID() }); AutowireCapableBeanFactory beanFactory = this.applicationContext.getAutowireCapableBeanFactory(); AsyncLockableOperationRunner operationRunner = beanFactory.createBean(AsyncLockableOperationRunner.class); beanFactory.initializeBean(operationRunner, new StringBuffer(this.getName()).append(System.currentTimeMillis()).toString()); operationRunner.setOperation(this); operationRunner.setContext(context); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor( new StringBuffer("exec").append(this.getName()).toString()); executor.submit(operationRunner); this.getLogger().debug("AsyncRunner of operation {} ({}) started with SimpleAsyncTaskExecutor", new Object[] { this.getName(), this.getUUID() }); }
From source file:minium.cucumber.MiniumCucumber.java
private void initializeInstance(Class<?> clazz, AutowireCapableBeanFactory beanFactory, Object testInstance) { try {//from w w w . ja v a2 s.c om beanFactory.autowireBeanProperties(testInstance, AutowireCapableBeanFactory.AUTOWIRE_NO, false); beanFactory.initializeBean(testInstance, clazz.getName()); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:org.jboss.arquillian.spring.integration.enricher.AbstractSpringInjectionEnricher.java
/** * <p>Injects dependencies into the test case.</p> * * @param applicationContext the {@link org.springframework.context.ApplicationContext} * @param testCase the test case for which the beans will be injected */// w ww .ja v a2 s. c o m private void injectDependencies(ApplicationContext applicationContext, Object testCase) { // for applications that do not contain Annotation post processors, create new // application context with those and create test class from that context StaticApplicationContext staticContext = new StaticApplicationContext(applicationContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(staticContext); staticContext.refresh(); // retrieves the bean factory AutowireCapableBeanFactory beanFactory = staticContext.getAutowireCapableBeanFactory(); // injects all the members beanFactory.autowireBeanProperties(testCase, AutowireCapableBeanFactory.AUTOWIRE_NO, false); // initialize the bean beanFactory.initializeBean(testCase, testCase.getClass().getName()); }
From source file:com.thinkbiganalytics.nifi.provenance.util.SpringApplicationContext.java
/** * Autowire an object/*from w ww .java2 s . co m*/ * * @param key the name of the Spring Bean * @param obj the Bean or Object you want to be included into Spring and autowired * @param force Force it to be autowired even if the bean is not registered with the appcontext. If the key is already registered in spring and this is false it will not autowire. * @return the autowired Spring object */ public Object autowire(String key, Object obj, boolean force) { Object bean = null; try { bean = SpringApplicationContext.getInstance().getBean(key); } catch (Exception e) { } if (bean == null || force) { try { if (applicationContext == null) { initializeSpring(); } if (applicationContext != null) { AutowireCapableBeanFactory autowire = getApplicationContext().getAutowireCapableBeanFactory(); autowire.autowireBean(obj); //fire PostConstruct methods autowire.initializeBean(obj, key); return obj; } else { log.error("Unable to autowire {} with Object: {}. ApplicationContext is null.", key, obj); } } catch (Exception e) { log.error("Unable to autowire {} with Object: {} ", key, obj); } } else if (bean != null) { return bean; } return null; }
From source file:org.apache.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);// ww w . j a va2 s . c o m assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); }