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

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

Introduction

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

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
        throws IllegalStateException 

Source Link

Document

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

Usage

From source file:example.WacuController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(this.servletContext);

    return new ModelAndView("wacu")//

            .addObject("applicationContextDisplayName", wac.getDisplayName())//

            .addObject("applicationContextClassName", wac.getClass().getName());

}

From source file:grails.plugin.miniprofiler.sitemesh.grails20.ProfilingGrailsPageFilter.java

@Override
public void init(FilterConfig fc) {
    super.init(fc);
    profilerProvider = WebApplicationContextUtils.getRequiredWebApplicationContext(fc.getServletContext())
            .getBean("profilerProvider", ProfilerProvider.class);

    Field field = null;//www.j a v  a 2  s.  c  o  m
    try {
        field = GrailsPageFilter.class.getDeclaredField("decoratorMapper");
        field.setAccessible(true);
        DecoratorMapper decoratorMapper = (DecoratorMapper) field.get(this);
        field.set(this, new ProfilingDecoratorMapper(decoratorMapper, profilerProvider));
    } catch (NoSuchFieldException e) {
        // different grails version which doesn't have that field?
    } catch (IllegalAccessException e) {
        // just won't work, we're in a security manager
    }
}

From source file:org.constretto.examples.dashboard.ConstrettoTaglibListener.java

public void contextInitialized(ServletContextEvent sce) {
    final WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sce.getServletContext());
    context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AUTOWIRE_BY_TYPE, true);
}

From source file:com.sbu.controller.Feed_Personal_Startup_View_Controller.java

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    startupService = context.getBean(StartupManager.class);
    memberService = context.getBean(MemberManager.class);
}

From source file:net.sf.appstatus.web.SpringObjectInstantiationListener.java

/**
 * Constructor.//from   ww w .  ja va2  s.  co  m
 * 
 * @param context
 *            Current servlet context.
 */
public SpringObjectInstantiationListener(ServletContext context) {
    webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
}

From source file:org.bytesoft.openjtcc.supports.spring.web.TransactionResourceAdapterListener.java

public void contextDestroyed(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();
    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    ResourceAdapter resourceAdapter = (ResourceAdapter) applicationContext.getBean(ResourceAdapter.class);
    resourceAdapter.stop();//ww w  .  j ava2 s. co m
}

From source file:org.ujorm.orm.support.OpenSessionInViewFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    ServletContext sc = filterConfig.getServletContext();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    ujoSessionFactoryFilter = (UjoSessionFactoryFilter) wac.getBean("ujoSessionFactory");
}

From source file:wangsd.ex.helloworld.spring.data.relationdb.viewer.HelloWorld.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w w  w. j a  v  a  2 s.  co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(this.getServletContext());
    ModelController controller = new ModelController(context);
    StringBuilder sb = new StringBuilder();
    sb.append(controller.initialize(10));
    sb.append(controller.fetchAll());
    sb.append(controller.findById(10));
    sb.append(controller.deleteById(5));

    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>ex-helloworld-spring-data-relationdb</title>");
        out.println("</head>");
        out.println("<body>");
        out.println(sb.toString());
        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.sbu.controller.ServletPersonalStartupController.java

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    startupService = context.getBean(StartupManager.class);
    memberService = context.getBean(MemberManager.class);
    members = new Vector<>();
}

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);//  w  w  w .j a  v  a2s  .c  om
        }
    }

    databaseMigration.migrate(locations);
}