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

ppt做仿网站点击效果优化大师怎么强力卸载

ppt做仿网站点击效果,优化大师怎么强力卸载,wordpress的live2D,推广优化seo1. ApplicationContext应用上下文获取方式 应用上下文对象是通过new ClasspathXmlApplicationContext(spring配置文件) 方式获取的,但是每次从容器中获得Bean时都要编写new ClasspathXmlApplicationContext(spring配置文件) ,这样的弊端是配置文件加载多…

1. ApplicationContext应用上下文获取方式

应用上下文对象是通过new ClasspathXmlApplicationContext(spring配置文件) 方式获取的,但是每次从容器中获得Bean时都要编写new ClasspathXmlApplicationContext(spring配置文件) ,这样的弊端是配置文件加载多次,应用上下文对象创建多次

在Web项目中,可以使用ServletContextListener监听Web应用的启动,我们可以在Web应用启动时,就加载Spring的配置文件,创建应用上下文对象ApplicationContext,在将其存储到最大的域servletContext域中,这样就可以在任意位置从域中获得应用上下文ApplicationContext对象了。
web.xml配置全局初始化参数

<!--全局初始化参数--><context-param><param-name>contextConfigLocation</param-name><param-value>applicationContext.xml</param-value></context-param><listener><listener-class>com.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坐标)

<dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.0.5.RELEASE</version>
</dependency>

② 使用WebApplicationContextUtils获得应用上下文对象ApplicationContext
配置web.xml

 <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
package 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.qdjiajiao.com/news/7035.html

相关文章:

  • b2b都有哪些平台seo排名平台
  • 用别人的资源做网站比较好的软文发布平台
  • 网站怎么看被百度收录营销策划方案案例
  • 南充市住房与城乡建设网站软文价格
  • 自己做返利网站吗seo网站管理
  • 花木企业网站源码东莞seo软件
  • 做app模板下载网站深圳百度国际大厦
  • 做网站组织结构框架例子windows优化软件
  • 常熟滨江开发区人才网内存优化大师
  • 廊坊哪里有做网站建设的百度指数下载手机版
  • 源码下载工具热狗seo顾问
  • 做民宿加盟哪些网站比较好石家庄疫情防控最新政策
  • 哪个网站看电影做便宜网上销售平台怎么做
  • 成都网站建设成都网络公司kol合作推广
  • 在线教育网站开发经验简历填写网店运营策划方案
  • 网站建设 成都今网科技北京seo业务员
  • 有没有在线制作app网站开发平台关键词优化公司如何选择
  • 自己做的网站响应速度慢seo排名工具有哪些
  • 做网站合肥哪家公司好一站式快速网站排名多少钱
  • 巴中网站建设培训班上海网站建设推广服务
  • wordpress官网无法注册青岛网站seo服务
  • 北海市住房和城乡建设局网站百度咨询电话 人工客服
  • 企业怎么在网站上做宣传百度推广多少钱一个月
  • 深圳做网站推广公司有效获客的六大渠道
  • js 访问网站统计刷新不增加次数优化seo是什么
  • 网页设计实训报告设计思路怎么制作seo搜索优化
  • 做网站有了空间在备案吗上海百度关键词优化公司
  • 个人音乐网站免费建设营销型网站建设实训总结
  • 网站建设构思seo案例分析方案
  • 网页网站设计公司排名营销软件app