当前位置: 首页 > news >正文

网站开发模合同实体店营销案例100例

网站开发模合同,实体店营销案例100例,简易网站模板,做网站设置时间1. ApplicationContext应用上下文获取方式 应用上下文对象是通过new ClasspathXmlApplicationContext(spring配置文件) 方式获取的#xff0c;但是每次从容器中获得Bean时都要编写new ClasspathXmlApplicationContext(spring配置文件) #xff0c;这样的弊端是配置文件加载多…1. ApplicationContext应用上下文获取方式 应用上下文对象是通过new ClasspathXmlApplicationContext(spring配置文件) 方式获取的但是每次从容器中获得Bean时都要编写new ClasspathXmlApplicationContext(spring配置文件) 这样的弊端是配置文件加载多次应用上下文对象创建多次。 在Web项目中可以使用ServletContextListener监听Web应用的启动我们可以在Web应用启动时就加载Spring的配置文件创建应用上下文对象ApplicationContext在将其存储到最大的域servletContext域中这样就可以在任意位置从域中获得应用上下文ApplicationContext对象了。 web.xml配置全局初始化参数 !--全局初始化参数--context-paramparam-namecontextConfigLocation/param-nameparam-valueapplicationContext.xml/param-value/context-paramlistenerlistener-classcom.zhxd.listener.ContextLoaderListener/listener-class /listener创建ServletContextListener package com.zhxd.listener;import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener;public class ContextLoaderListener implements ServletContextListener {public void contextInitialized(ServletContextEvent servletContextEvent) {ServletContext servletContext servletContextEvent.getServletContext();//ClassPathXmlApplicationContext app new ClassPathXmlApplicationContext(applicationContext.xml);//隐藏Spring配置文件String contextConfigLocation servletContext.getInitParameter(contextConfigLocation);ClassPathXmlApplicationContext app new ClassPathXmlApplicationContext(contextConfigLocation);servletContext.setAttribute(app,app);System.out.println(容器创建完毕...);}public void contextDestroyed(ServletContextEvent servletContextEvent) {} }UserServlet.java public class UserServlet extends HttpServlet {Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {ServletContext servletContext req.getServletContext();ApplicationContext app (ApplicationContext)servletContext.getAttribute(app);UserService userService app.getBean(UserService.class);userService.save();} }优化上述程序把上下文变量名字app隐藏 定义获取上下文对象工具类 package com.zhxd.listener;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletContext; import javax.servlet.ServletContextListener;public class WebApplicationContextUtils {public static ApplicationContext getApp(ServletContext servletContext) {return (ApplicationContext) servletContext.getAttribute(app);} }修改UserServlet.java public class UserServlet extends HttpServlet {Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {ServletContext servletContext req.getServletContext();ApplicationContext app WebApplicationContextUtils.getApp(servletContext);UserService userService app.getBean(UserService.class);userService.save();} }2.Spring提供获取应用上下文的工具 上面的分析不用手动实现Spring提供了一个监听器ContextLoaderListener就是对上述功能的封装该监听器内部加载Spring配置文件创建应用上下文对象并存储到ServletContext域中提供了一个客户端工具WebApplicationContextUtils供使用者获得应用上下文对象。 所以我们需要做的只有两件事 ① 在web.xml中配置ContextLoaderListener监听器导入spring-web坐标 dependencygroupIdorg.springframework/groupIdartifactIdspring-web/artifactIdversion5.0.5.RELEASE/version /dependency② 使用WebApplicationContextUtils获得应用上下文对象ApplicationContext 配置web.xml context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:applicationContext.xml/param-value/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerpackage com.zhxd.web;import com.zhxd.service.UserService; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils;import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;public class UserServlet extends HttpServlet {Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {ServletContext servletContext req.getServletContext();WebApplicationContext app WebApplicationContextUtils.getWebApplicationContext(servletContext);UserService userService app.getBean(UserService.class);userService.save();} }
http://www.w-s-a.com/news/225439/

相关文章:

  • 设备网站模板江西的赣州网站建设
  • 邯郸营销型网站国际招聘人才网
  • hexo wordpress 主题织梦网站优化教程
  • 网站建设方案及上海市建设协会网站
  • 轴承外贸网站怎么做南宁网站排名优化公司哪家好
  • 沈阳企业网站建站郴州优化公司
  • cctv5+手机在线直播观看seo关键词排名优化方法
  • 网站建设公司怎么谈单怎么开通微信小程序商店
  • 深圳做网站案例一个服务器可以备案几个网站
  • 网络营销策划名词解释泉州百度推广排名优化
  • 一键生成网站的软件互联网营销师是干什么
  • 网站后台管理水印怎么做手机优化设置
  • 哪个网站做图文素材多wordpress++优化
  • 建设网站就选用什么样的公司网站类型分类有哪些
  • 找平面设计师网站网站建设须知
  • 建设联结是不是正规网站wordpress 微博同步
  • 瑞安微网站建设广州推广
  • 做旅游宣传网站的流程图中国企业集成网电子商务
  • 开发商城网站开发成交功能网站
  • 网站建设公司专业公司排名搭建网站的企业
  • 网站建设难吗海南智能网站建设报价
  • 企业网站建设选题的依据及意义校园网站建设的论文
  • 网站版面设计方案水电维修在哪个网站上做推广好些
  • 邹平建设局官方网站企业宣传片广告公司
  • 南京建设集团网站建站极速通
  • 网站建设与推广员岗位职责网站开发应如何入账
  • 企业网站的作用和目的手机回收站
  • 大连零基础网站建设培训电话郎溪做网站
  • 成都科技网站建设注册公司最少需要多少注册资金
  • 找公司做网站注意事项麻城建设局网站停办