1.要让我们的网站性能更好,那么有的东西是需要做静态化的。做静态化步骤:

  1.1在web.xml中配置监听器

  1.2.创建一个bean用来实现静态化

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>aa</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- shiro过滤器定义 -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<!-- 该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理 -->
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>com.open1111.service.impl.InitComponet</listener-class>
</listener>

<!-- 添加对springmvc的支持 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

</web-app>

2.创建初始化组件类:

package com.open1111.service.impl;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
* 初始化组件
* @author user
*
*/
@Component("initComponet")
public class InitComponet implements ApplicationContextAware,ServletContextListener{

private static ApplicationContext applicationContext;

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// TODO Auto-generated method stub
this.applicationContext=applicationContext;
System.out.println(this);
}

/**
* 刷新application缓存方法
* @param application
*/
public void refreshSystem(ServletContext application){

}

public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
ServletContext application=sce.getServletContext();
refreshSystem(application);
}

public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub

}

}

最新文章

  1. bzoj 1334: [Baltic2008]Elect
  2. Samba日志分析
  3. [vijos P1180] 选课
  4. 【洛谷P1378】油滴扩展
  5. Canvas -画图 关键字
  6. Layer弹层组件 二次扩展,项目中直接使用。
  7. MacBook 经常使用快捷键
  8. C# 委托高级应用----线程——创建无阻塞的异步调用(二)
  9. 你不知道的JavaScript--Item2 浮点数精度
  10. Hadoop配置第1节-集群网络配置
  11. 做了5年的Android,我转Java后台了!
  12. 代码d17
  13. [VUE ERROR] Duplicate keys detected: &#39;tab-user&#39;. This may cause an update error.
  14. 风险指针(Hazard Pointer) 内存空间共享模型
  15. XP局域网访问无权限、不能互相访问问题的完整解决方案
  16. MySQL5.7.11免安装版的安装和配置:解决MYSQL 服务无法启动问题
  17. css transition transform animation例子讲解
  18. September 15th 2017 Week 37th Friday
  19. CentOS 6.5 下搭建FastDFS服务
  20. IntelliJ IDEA 左侧显示/展开类中的方法

热门文章

  1. .net core 第一个mvc项目目录结构简析
  2. FreeSql 新功能介绍:贪婪加载五种方法
  3. OpenStack基础知识-单元测试工具介绍
  4. Java实现发送邮箱验证码/注册验证链接
  5. EOS 数据签名与公匙验证代码用例
  6. String类、static、Arrays类、Math类
  7. checkbox,不选中传值
  8. 使用命令行+代理更新Android SDK
  9. MD5WLBUtil
  10. (转)TComboBox patch for Delphi 7