Spring Tool class: Webapplicationcontextutils

Source: Internet
Author: User


Webapplicationcontextutils can get

Webapplicationcontextwebapplicationcontext can fetch the bean and then execute the method to get the data.


package cn.sccl.common.web;import java.util.list;import java.util.map;import  javax.servlet.servletcontext;import javax.servlet.servletcontextevent;import  javax.servlet.servletcontextlistener;import org.apache.commons.logging.log;import  org.apache.commons.logging.logfactory;import org.springframework.context.applicationcontext;import  org.springframework.web.context.contextloaderlistener;import  org.springframework.web.context.support.webapplicationcontextutils;import  cn.sccl.common.service.bizcodemanager;import cn.sccl.common.web.util.log4jwebconfigurer;import  cn.sccl.pms.model.division;import cn.sccl.pms.model.divisionquery;import  cn.sccl.pms.service.divisionmanager;public class startuplistener extends  contextloaderlistener implements servletcontextlistener {@Overridepublic  void  Contextinitialized (servletcontextevent event)  {super.contextinitialized (evenT); Servletcontext context = event.getservletcontext ();//Get servletcontext//can also be obtained in the implementation of the HttpServlet interface, Servletcontext servletcontext = this.getservletcontext ();   setupcontext (context);} Protected void setupcontext (Final servletcontext context)  {//  Webapplicationcontext ctx = webapplicationcontextutils.getwebapplicationcontext (ServletContext) It is recommended to use this, because getrequiredwebapplicationcontext requires that the ServletContext must have applicationcontextapplicationcontext in the  //.  ctx = webapplicationcontextutils.getrequiredwebapplicationcontext (context); //  Administrative divisions    DivisionManager divisionManager =  (Divisionmanager)  ctx.getbean (" Divisionmanager ");//Get Managerlist<division> divisions = divisionmanager.query (new  Divisionquery ());//Put data in the servletcontext  page and get it in application. Because application and ServletContext correspond to Context.setattribute ("divisions",  divisions);}}


This article is from the "Jianbo" blog, make sure to keep this source http://jianboli.blog.51cto.com/12075002/1890712

Spring Tool class: Webapplicationcontextutils

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.