问题描述
启动的时候,发现Tomcat7.0.50用了大量的时间去加载mime,而且每次执行一个action请求,它就疯狂的再来加载mime,服务器加载日志Initializing Spring root WebApplicationContext定在这里,打印信息如下:<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="2.4" metadata-complete="true"> <display-name>Struts 2 - Maven Archetype - Starter</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext*.xml</param-value> </context-param> <filter> <filter-name>struts2-prepare</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class> <async-supported>false</async-supported> </filter> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> <async-supported>false</async-supported> </filter> <filter> <filter-name>struts2-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> <async-supported>false</async-supported> </filter> <filter-mapping> <filter-name>struts2-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2-execute</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>fork</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>xpoweredBy</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>classdebuginfo</param-name> <param-value>true</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jspx</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> <cookie-config> </cookie-config> </session-config> <mime-mapping> <extension>fh7</extension> <mime-type>image/x-freehand</mime-type> </mime-mapping> <mime-mapping> <extension>fh5</extension> <mime-type>image/x-freehand</mime-type> </mime-mapping>...这里省略N多的mime加载 <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list>我只部署了一个项目,我想不明白这个mime加载时设置在哪里的,我有什么办法避免这个问题。
解决方案
楼主你好,这类MIME的信息,是配置在tomcat的conf目录下的web.xml文件中,<!-- ===================== Default MIME Type Mappings =================== --> <!-- When serving static resources, Tomcat will automatically generate --> <!-- a "Content-Type" header based on the resource's filename extension, --> <!-- based on these mappings. Additional mappings can be added here (to --> <!-- apply to all web applications), or in your own application's web.xml --> <!-- deployment descriptor. --> <mime-mapping> <extension>123</extension> <mime-type>application/vnd.lotus-1-2-3</mime-type> </mime-mapping> <mime-mapping> <extension>3dml</extension> <mime-type>text/vnd.in3d.3dml</mime-type> </mime-mapping> <mime-mapping> <extension>3g2</extension> <mime-type>video/3gpp2</mime-type> </mime-mapping>这类配置主要用来影响静态资源时生成Content-Type的。所以你看到的都是这里配置的。每个部署在Tomcat中的Java Web应用,其配置最终是WEB-INF/web.xml和tomcat自带的这个web.xml合并起来生成具体的配置信息的。你可以手动修改它。
解决方案二:
好像有一个配置文件,配置一个监听器
解决方案三:
看你的spring配置文件是否配置在启动时候检查表了,更新表结构之类的如:<prop key="hibernate.hbm2ddl.auto">update</prop>