Example usage for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext.

Prototype

@Nullable
public static WebApplicationContext getWebApplicationContext(ServletContext sc) 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:de.u808.simpleinquest.web.tags.MimeIconTag.java

private void initMimeIconRegistry() {
    ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(((PageContext) getJspContext()).getServletContext());
    this.mimeIconRegistry = (MimeIconRegistry) context.getBean("mimeIconRegistry");
}

From source file:org.apache.archiva.redback.integration.filter.SpringServletFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext());

}

From source file:rights.HasAllRightsTag.java

private boolean hasBranchRights() {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(pageContext.getServletContext());
    branchRightsHolder = applicationContext.getBean(BranchRightsHolder.class);
    return branchRightsHolder.isRight(url, branchId);
}

From source file:com.telefonica.euro_iaas.paasmanager.bootstrap.SynchronizationBoostrap.java

/** {@inheritDoc} */
public void contextInitialized(ServletContextEvent event) {
    log.info("SynchronizationBootstrap. START");
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());

    log.info("SynchronizationBootstrap. FINISH");
}

From source file:com.norteksoft.security.web.listener.SecurityContextListener.java

private Object getBeanFromApplicationContext(ServletContext servletContext, String beanName) {
    ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    WebContextUtils.setContext(applicationContext);
    ContextUtils.setContext(applicationContext);
    Object object = applicationContext.getBean(beanName);
    if (object == null) {
        StringBuilder builder = new StringBuilder();
        builder.append("Bean[").append(beanName).append("],?");
        throw new RuntimeException(builder.toString());
    }//from   ww w .java 2 s  .  c  om
    return object;
}

From source file:web.mvc.servlets.MyServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    if (context == null) {
        request.getRequestDispatcher("WEB-INF/jsp/db-info-error.jsp").forward(request, response);
    }/*from   w w w . j av  a  2s. com*/

    DriverManagerDataSource dataSource = context.getBean(DriverManagerDataSource.class);
    List<InfoItem> data = new ArrayList<>();
    try {
        fillDataFromDataSource(data, dataSource);
    } catch (SQLException ex) {
        Logger.getLogger(MyServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    request.setAttribute("info", data);
    request.getRequestDispatcher("WEB-INF/jsp/db-info.jsp").forward(request, response);
}

From source file:com.solab.alarms.servlet.AlarmServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    WebApplicationContext ctxt = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    sender = ctxt.getBean(AlarmSenderImpl.class);
    auth = ctxt.getBean(PasswordVerifier.class);
}

From source file:it.pronetics.madstore.crawler.impl.grid.support.MadStoreGridListener.java

public void contextInitialized(ServletContextEvent event) {
    if (MadStoreConfigurationManager.getInstance().getMadStoreConfiguration().isGridModeEnabled()) {
        ApplicationContext context = WebApplicationContextUtils
                .getWebApplicationContext(event.getServletContext());
        Collection beans = context.getBeansOfType(MadStoreGrid.class).values();
        try {// w  w  w. j  a v  a2 s .  c  o m
            if (beans.size() == 1) {
                madstoreGrid = (MadStoreGrid) beans.iterator().next();
                madstoreGrid.startGrid();
            } else if (beans.size() == 0) {
                throw new IllegalStateException("No grid factory found in Spring application context!");
            } else {
                throw new IllegalStateException(
                        "More than one grid factory found in Spring application context!");
            }
        } catch (GridException ex) {
            throw new RuntimeException("Error during grid startup", ex);
        }
    }
}

From source file:jahspotify.web.tags.TrackStatisticsTag.java

@Override
protected int doStartTagInternal() throws Exception {
    final HistoricalStorage historicalStorage = WebApplicationContextUtils
            .getWebApplicationContext(pageContext.getServletContext()).getBean(MongoDBHistoricalStorage.class);
    final TrackStatistics trackStatistics = historicalStorage.getTrackStatistics(Link.create(_link));
    pageContext.setAttribute(_var, trackStatistics);
    return Tag.SKIP_BODY;

}

From source file:org.activiti.explorer.servlet.ExplorerApplicationServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());
}