对SSM框架中所要用到的配置文件进行解释说明(针对注解形式)
在spring+springmvc+mybatis框架中用到
三个XML配置文件:
1、web.xml(web项目都会有的配置文件,更是关联整个项目的配置)
2、spring-mvc.xml(包含springmvc的一些相关配置)
3、spring-mybatis.xml(mybatis的相关配置)
两个资源属性文件:
1、jdbc.properties(关于jdbc的配置,提取出来方便以后对数据库的修改)
2、log4j.properties(日志文件的配置)
<?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_3_0.xsd"
version="3.0">
<context-param> <!--全局范围内环境参数初始化-->
<param-name>contextConfigLocation</param-name> <!--参数名称-->
<param-value>classpath:spring-mybatis.xml</param-value> <!--参数取值-->
</context-param>
<!--以下配置的加载顺序:先 ServletContext >> context-param >> listener >> filter >> servlet >> spring-->
<!---------------------------------------------------过滤器配置------------------------------------------------------>
<!--例:编码过滤器-->
<filter> <!-- 用来声明filter的相关设定,过滤器可以截取和修改一个Servlet或JSP页面的请求或从一个Servlet或JSP页面发出的响应-->
<filter-name>encodingFilter</filter-name> <!--指定filter的名字-->
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <!--定义filter的类的名称-->
<async-supported>true</async-supported> <!--设置是否启用异步支持-->
<init-param><!--用来定义参数,若在Servlet可以使用下列方法来获得:String param_name=getServletContext().getInitParamter("param-name里面的值");-->
<param-name>encoding</param-name> <!--参数名称-->
<param-value>UTF-8</param-value> <!--参数值-->
</init-param>
</filter>
<filter-mapping><!--用来定义filter所对应的URL-->
<filter-name>encodingFilter</filter-name> <!--指定对应filter的名字-->
<url-pattern>/*</url-pattern> <!--指定filter所对应的URL-->
</filter-mapping>
<!---------------------------------------------------监听器配置------------------------------------------------------>
<!--例:spring监听器-->
<listener> <!--用来设定Listener接口-->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class><!--定义Listener的类名称-->
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!---------------------------------------------------servlet配置------------------------------------------------------>
<servlet> <!--用来声明一个servlet的数据 -->
<servlet-name>SpringMVC</servlet-name> <!--指定servlet的名称-->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--指定servlet的类名称,这里配置了前端控制器-->
<init-param><!--用来定义参数,可有多个init-param。在servlet类中通过getInitParamenter(String name)方法访问初始化参数 -->
<param-name>contextConfigLocation</param-name> <!--参数名称-->
<param-value>classpath:spring-mvc.xml</param-value> <!--参数值-->
</init-param>
<load-on-startup>1</load-on-startup><!--当值为正数或零时:Servlet容器先加载数值小的servlet,再依次加载其他数值大的servlet.-->
<async-supported>true</async-supported><!--设置是否启用异步支持-->
</servlet>
<servlet-mapping><!--用来定义servlet所对应的URL-->
<servlet-name>SpringMVC</servlet-name> <!--指定servlet的名称-->
<url-pattern>/</url-pattern> <!--指定servlet所对应的URL-->
</servlet-mapping>
<!-----------------------------------------------会话超时配置(单位为分钟)------------------------------------------------->
<session-config><!--如果某个会话在一定时间未被访问,则服务器可以扔掉以节约内存-->
<session-timeout>120</session-timeout>
</session-config>
<!---------------------------------------------------MIME类型配置 ------------------------------------------------------>
<mime-mapping><!--设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开-->
<extension>*.ppt</extension> <!--扩展名名称-->
<mime-type>application/mspowerpoint</mime-type> <!--MIME格式-->
</mime-mapping>
<!---------------------------------------------------欢迎页面配置 ------------------------------------------------------>
<welcome-file-list><!--定义首页列单.-->
<welcome-file>/index.jsp</welcome-file> <!--用来指定首页文件名称.我们可以用<welcome-file>指定几个首页,而服务器会依照设定的顺序来找首页.-->
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
<!---------------------------------------------------配置错误页面------------------------------------------------------>
<error-page> <!--将错误代码(Error Code)或异常(Exception)的种类对应到web应用资源路径.-->
<error-code>404</error-code> <!--HTTP Error code,例如: 404、403-->
<location>error.html</location> <!--用来设置发生错误或异常时要显示的页面-->
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type><!--设置可能会发生的java异常类型,例如:java.lang.Exception-->
<location>ExceptionError.html</location> <!--用来设置发生错误或异常时要显示的页面-->
</error-page>
</web-app>