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

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

Introduction

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

Prototype

void autowireBean(Object existingBean) throws BeansException;

Source Link

Document

Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g.

Usage

From source file:ca.travelagency.utils.AutowiredUtils.java

public static void autowire(ServletContext servletContext, Object existingBean) {
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(servletContext);
    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(existingBean);
}

From source file:org.uimafit.spring.util.ResourceInitializationUtil.java

/**
 * Initialize an existing object as a Spring bean.
 *///from  w  w w  . j  a va 2 s.c  om
public static <T> T initializeBean(AutowireCapableBeanFactory aBeanFactory, T aBean, String aName) {
    @SuppressWarnings("unchecked")
    T wrappedBean = (T) aBeanFactory.initializeBean(aBean, aName);
    aBeanFactory.autowireBean(aBean);
    return wrappedBean;
}

From source file:org.lightadmin.core.config.domain.unit.ConfigurationUnitsConverter.java

private static AdministrationConfiguration autowiredConfigurationInstance(final Class configurationClass,
        AutowireCapableBeanFactory beanFactory) {
    final AdministrationConfiguration configurationInstance = configurationInstance(configurationClass);
    beanFactory.autowireBean(configurationInstance);
    return configurationInstance;
}

From source file:com.trenako.web.tags.SpringTagSupport.java

private void init() {
    WebApplicationContext wac = getRequestContext().getWebApplicationContext();
    AutowireCapableBeanFactory acbf = wac.getAutowireCapableBeanFactory();
    acbf.autowireBean(this);
}

From source file:com.fpmislata.banco.presentation.database.ServerContextListenerImpl.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("Iniciando");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sce.getServletContext());
    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    databaseMigration.migrate();/*  w w w  .j av  a  2  s. c o  m*/

}

From source file:org.lightadmin.core.view.tags.AbstractAutowiredTag.java

@Override
public void setJspContext(JspContext context) {
    super.setJspContext(context);

    AutowireCapableBeanFactory beanFactory = (AutowireCapableBeanFactory) context
            .findAttribute(ApplicationController.BEAN_FACTORY_KEY);
    beanFactory.autowireBean(this);
}

From source file:es.logongas.ix3.web.database.DatabaseMigrateContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContextEvent.getServletContext());
    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    //Permitirmos varias "locations" en el parmetro separados por "\n"
    String[] rawLocations = (servletContextEvent.getServletContext()
            .getInitParameter("databasemigration.location") + "").split("\\n");
    List<String> locations = new ArrayList<String>();
    for (String location : rawLocations) {
        if ((location != null) && (location.trim().isEmpty() == false)) {
            locations.add(location);/* ww  w . j  av a2  s  .  co  m*/
        }
    }

    databaseMigration.migrate(locations);
}

From source file:org.echocat.jomon.spring.testing.environments.BeanEnvironment.java

protected void autowire(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull Object bean) {
    final AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(bean);
}

From source file:com.thinkbiganalytics.nifi.provenance.util.SpringApplicationContext.java

/**
 * Autowire an object//from  w  w  w  .j  a  v  a2 s.  c  om
 *
 * @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:edu.dfci.cccb.mev.dataset.rest.configuration.RDispatcherConfiguration.java

@Bean
@Rserve//from  www .  j  ava2  s .  c o  m
public Module rserveDatasetSerializationModule(final AutowireCapableBeanFactory factory) {
    log.info("Configuring Rserve json serialization");
    return new SimpleModule() {
        private static final long serialVersionUID = 1L;

        {
            addSerializer(Dataset.class, new RserveDatasetSerializer());
            addSerializer(Double.class, new RserveDoubleSerializer());
            addSerializer(double.class, new RserveDoubleSerializer());

            addDeserializer(Double.class, new RserveDoubleDeserializer());
            addDeserializer(double.class, new RserveDoubleDeserializer());
            addDeserializer(Dataset.class, new RserveDatasetDeserializer());
        }

        private void inject(Object instance) {
            factory.autowireBean(instance);
        }

        @Override
        public <T> SimpleModule addSerializer(Class<? extends T> type, JsonSerializer<T> ser) {
            inject(ser);
            return super.addSerializer(type, ser);
        }

        @Override
        public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser) {
            inject(deser);
            return super.addDeserializer(type, deser);
        }
    };
}