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

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

Introduction

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

Prototype

int AUTOWIRE_NO

To view the source code for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_NO.

Click Source Link

Document

Constant that indicates no externally defined autowiring.

Usage

From source file:com.extjs.djn.spring.loader.SpringLoaderHelper.java

/**
 * Allow to autowired a non spring instanciated object
 * /*from  ww  w  .  j a  v  a  2  s . c  om*/
 * @param objToLoad
 * @param prefixBeanName
 */
public static void autowireBean(Object objToLoad, String prefixBeanName) {
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ContextLoader
            .getCurrentWebApplicationContext().getAutowireCapableBeanFactory();
    beanFactory.autowireBeanProperties(objToLoad, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    beanFactory.initializeBean(objToLoad, prefixBeanName);
}

From source file:net.easysmarthouse.ui.webui.server.ServerBaseServlet.java

private void initServerContext() {
    WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    //for populate existing bean instances that Spring does not control the lifecycle of
    AutowireCapableBeanFactory beanFactory = wac.getAutowireCapableBeanFactory();
    beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    beanFactory.initializeBean(this, this.getClass().getName());
}

From source file:com.laxser.blitz.util.SpringUtils.java

/**
 * @param clazz/*  w  ww  .jav a 2s  .  c  o  m*/
 * @param context
 * @return
 */
public static <T> T createBean(Class<?> clazz, ApplicationContext context) {
    @SuppressWarnings("unchecked")
    T bean = (T) context.getAutowireCapableBeanFactory().createBean(clazz,
            AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    if (logger.isDebugEnabled()) {
        logger.debug("create spring bean: " + bean.getClass() + "@" + bean.hashCode());
    }
    return bean;
}

From source file:ar.com.cema.methodology.analyzer.ui.servlet.DependencyInjectionHttpServlet.java

@Override
public final void init() throws ServletException {
    try {//from   ww  w  .j  a v a 2  s .c om
        ApplicationContext ctx = getApplicationContext();
        AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory();
        beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
        beanFactory.initializeBean(this, getClass().getName());
    } catch (Exception e) {
        throw new ServletException(
                "Error injecting dependencies on servlet '" + getServletName() + "': " + e.getMessage(), e);
    }
    postInit();
}

From source file:jrouter.spring.SpringObjectFactory.java

@Override
public <T> T newInstance(Class<T> clazz) {
    if (AutowireCapableBeanFactory.AUTOWIRE_NO == autowireMode)
        return autowireCapableBeanFactory.createBean(clazz);
    return (T) autowireCapableBeanFactory.createBean(clazz, autowireMode, false);
}

From source file:com.laxser.blitz.util.SpringUtils.java

/**
 * @param bean//from   www . j  ava2 s .com
 * @param context
 */
public static <T> T autowire(T bean, ApplicationContext context) {
    context.getAutowireCapableBeanFactory().autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO,
            false);
    @SuppressWarnings("unchecked")
    T ret = (T) context.getAutowireCapableBeanFactory().initializeBean(bean, bean.getClass().getName());
    return ret;
}

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:com.epam.ta.reportportal.auth.PermissionsRegisterBean.java

@SuppressWarnings("unchecked")
@Override//from w  ww .  ja v  a2s  .c om
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    Map<String, Permission> permissionBeans = beanFactory.getBeansOfType(Permission.class);
    Map<String, Permission> permissionsMap = beanFactory.getBean("permissionsMap", Map.class);
    for (Entry<String, Permission> permission : permissionBeans.entrySet()) {
        /*
         * There will be no NPE since we asked bean factory to get beans
         * with this annotation
         */
        for (String permissionName : permission.getValue().getClass().getAnnotation(LookupPermission.class)
                .value()) {
            /*
             * TODO add check for type before doing this
             */
            Permission permissionBean = permission.getValue();
            beanFactory.autowireBeanProperties(permissionBean, AutowireCapableBeanFactory.AUTOWIRE_NO, true);
            permissionsMap.put(permissionName, permissionBean);
        }
    }
}

From source file:com.zenika.stripes.contrib.spring.SpringNameBasedActionResolver.java

/**
 * Helper method to construct and return a new ActionBean instance. Called whenever a new
 * instance needs to be manufactured. Provides a convenient point for subclasses to add
 * specific behaviour during action bean creation.
 * /*  w  ww  .  j ava  2  s  . c  o  m*/
 * ActionBean are instancied from the Spring factory AutowireCapableBeanFactory.
 * @see <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-beans/3.0.2.RELEASE/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java#AbstractAutowireCapableBeanFactory.createBean%28java.lang.Class%29">createBean code</a>
 *
 * @param type the type of ActionBean to create
 * @param context the current ActionBeanContext
 * @return the new ActionBean instance
 * @throws Exception if anything goes wrong!
 */
@Override
protected ActionBean makeNewActionBean(Class<? extends ActionBean> type, ActionBeanContext context) {
    ServletContext servletContext = StripesFilter.getConfiguration().getServletContext();
    ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    ActionBean actionBean = (ActionBean) beanFactory.createBean(type, AutowireCapableBeanFactory.AUTOWIRE_NO,
            false);

    return actionBean;
}

From source file:org.usergrid.benchmark.commands.ToolBase.java

public void startSpring() {

    // copy("/testApplicationContext.xml", TMP);

    String[] locations = { "benchmark-context.xml" };
    ApplicationContext ac = new ClassPathXmlApplicationContext(locations);

    AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory();
    acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    acbf.initializeBean(this, "tool");

}