Example usage for org.springframework.web.context WebApplicationContext getAutowireCapableBeanFactory

List of usage examples for org.springframework.web.context WebApplicationContext getAutowireCapableBeanFactory

Introduction

In this page you can find the example usage for org.springframework.web.context WebApplicationContext getAutowireCapableBeanFactory.

Prototype

AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;

Source Link

Document

Expose AutowireCapableBeanFactory functionality for this context.

Usage

From source file:demo.order.MsgDelivererImpl.java

/**
 * Instead of @Autowired/ extends SpringBeanAutowiringSupport which doesn't work.
 *//*from   ww w  .ja va2s .c  o  m*/
private void wireBeans() {

    ServletContext servletContext;
    servletContext = (ServletContext) context.getMessageContext().get("javax.xml.ws.servlet.context");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    consumer = (Consumer) webApplicationContext.getAutowireCapableBeanFactory().getBean("consumer");

    //        executorService = (ExecutorService) webApplicationContext.getAutowireCapableBeanFactory().getBean("executorService");

}

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);/*from w  ww.j  av  a 2s. c o m*/
        }
    }

    databaseMigration.migrate(locations);
}

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.nkapps.billing.webservices.AccountWebService.java

private Object getBean(String beanName) {

    ServletContext servletContext = (ServletContext) context.getMessageContext()
            .get("javax.xml.ws.servlet.context");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    return webApplicationContext.getAutowireCapableBeanFactory().getBean(beanName);
}

From source file:org.onebusaway.webapp.impl.WebappServiceServletImpl.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    WebApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    context.getAutowireCapableBeanFactory().autowireBean(this);
}

From source file:org.grails.plugin.batch.Launcher.java

public void init(String[] args) {
    logDebug(true, "init(): begin");
    synchronized (initLock) {

        logDebug(true, "init(): this classLoader ", this.getClass().getClassLoader());
        logDebug(true, "init(): thread classLoader ", Thread.currentThread().getContextClassLoader());

        logDebug(true, "init(): env ", Environment.getCurrent());

        String resourcePath = getSystemProperty("resourcePath", null);
        if (resourcePath == null) {
            resourcePath = "war";
        }/*w  ww  .  ja  va  2 s  .c om*/

        logDebug(true, "init(): resourcePath ", resourcePath);

        servletContext = resourcePath != null ? new MockServletContext(resourcePath) : new MockServletContext();
        servletContext.setAttribute("args", args);

        servletContextListeners = new ServletContextListener[] { new Log4jConfigListener(),
                new GrailsContextLoaderListener() };

        this.shutdownHook = new Thread() {

            public void run() {
                logDebug(true, "shutdown hook run():");
                Launcher.this.destroy();
            }
        };

        this.destroyed = false;

        Runtime.getRuntime().addShutdownHook(this.shutdownHook);
        logDebug(true, "init(): shutdown hook added");

        try {
            ServletContextEvent event = new ServletContextEvent(servletContext);
            for (ServletContextListener l : servletContextListeners) {
                l.contextInitialized(event);
            }
        } catch (RuntimeException e) {
            log.error("init()", e);
            throw e;
        }

        logDebug("init(): thread classLoader ", Thread.currentThread().getContextClassLoader());

        GrailsApplication grailsApplication = ApplicationHolder.getApplication();
        DefaultGrailsMainClass main = getMainClass(grailsApplication);

        if (main != null) {
            final Object instance = main.getReferenceInstance();

            WebApplicationContext webContext = (WebApplicationContext) grailsApplication.getMainContext();
            webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance,
                    AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
            main.callInit();
        }

        logDebug("init(): end");
    }
}

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

/**
 * //from w w w .  j  ava  2 s .  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: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()}.
 *//*from   w w  w . j a va2s  . 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:nc.noumea.mairie.organigramme.core.authentification.AuthentificationFilter.java

public void init(FilterConfig config) throws ServletException {
    ServletContext servletContext = config.getServletContext();
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(servletContext);

    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();

    radiWSConsumer = (IRadiWSConsumer) autowireCapableBeanFactory.getBean("radiWSConsumer");
    sirhWSConsumer = (ISirhWSConsumer) autowireCapableBeanFactory.getBean("sirhWSConsumer");
}

From source file:util.ServerAppConfig.java

@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {

    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
    if (wac == null) {
        throw new IllegalStateException("Failed to find WebApplicationContext. "
                + "Was org.springframework.web.context.ContextLoader used to load the WebApplicationContext?");
    }/*from  w w  w  .  j  av  a  2 s.co m*/

    Map<String, T> beans = wac.getBeansOfType(endpointClass);
    if (beans.isEmpty()) {
        // Initialize a new bean instance
        return wac.getAutowireCapableBeanFactory().createBean(endpointClass);
    }
    if (beans.size() == 1) {
        // Return the matching bean instance
        return beans.values().iterator().next();
    } else {
        // This should never happen (@ServerEndpoint has a single path mapping) ..
        throw new IllegalStateException("Found more than one matching beans of type " + endpointClass);
    }
}