Example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory autowireBeanProperties

List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory autowireBeanProperties

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory autowireBeanProperties.

Prototype

void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
        throws BeansException;

Source Link

Document

Autowire the bean properties of the given bean instance by name or type.

Usage

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);//from  www .j ava2  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.  java2s. c om

    // 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.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.j  av 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: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 .  j  av  a  2 s  .  co  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:minium.cucumber.MiniumCucumber.java

private void initializeInstance(Class<?> clazz, AutowireCapableBeanFactory beanFactory, Object testInstance) {
    try {//w w w  .  ja  va 2s .  c o m
        beanFactory.autowireBeanProperties(testInstance, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
        beanFactory.initializeBean(testInstance, clazz.getName());
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:se.trillian.goodies.stripes.spring.SpringRuntimeConfiguration.java

/**
 * Autowires all properties for this configuration by retrieving the Spring
 * web application context and calls {@link DefaultConfiguration#init()}.
 *///  w w  w.j  av a 2  s  .  c  o m
@Override
public void init() {
    WebApplicationContext springContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
    beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);

    super.init();
}

From source file:com.mb.framework.web.filter.ReqRespLoggerFilter.java

/**
 * //from   w  w w. j a v a2s  . c om
 * This method is not implemented
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {

    ServletContext servletContext = filterConfig.getServletContext();

    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(servletContext);

    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();

    autowireCapableBeanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);

    logger.trace("This method implementation not needed");
}

From source file:org.jacpfx.spring.launcher.SpringJavaConfigLauncher.java

@Override
public <P> P registerAndGetBean(Class<? extends P> type, String id, Scope scope) {
    if (contains(id))
        return getBean(id);
    final GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(type);/*from   ww  w  .  j a v  a2s  .com*/
    if (scope != null)
        beanDefinition.setScope(scope.getType());
    beanDefinition.setAutowireCandidate(true);
    lock.writeLock().lock();
    try {
        final AutowireCapableBeanFactory factory = getContext().getAutowireCapableBeanFactory();
        final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory;
        registry.registerBeanDefinition(id, beanDefinition);
        factory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    } finally {
        lock.writeLock().unlock();
    }
    return getBean(id);
}