Spring mvc项目的web.xml以及注释

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app id="WebApp_ID" version="3.0"
  3.    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  5.  
  6.  
  7.    <context-param>
  8.       <param-name>log4jConfigLocation</param-name>
  9.       <param-value>classpath:config/properties/log4j.properties</param-value>
  10.    </context-param>
  11.  
  12.    <listener>
  13.       <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  14.    </listener>
  15.  
  16. <!-- context-param中配置的contextConfigLocation只对ContextLoaderListener有效 不会对DispatcherServlet有效 -->
  17. <!-- DispatcherServlet用来加载mvc相关的bean ContextLoaderListener用来加载其他bean -->
  18. <!-- ContextLoaderListener会生成一个spring的context 注:DispatcherServlet不会识别@controller注解-->
  19.    <context-param>
  20.       <param-name>contextConfigLocation</param-name>
  21.       <param-value>/WEB-INF/config/spring-bean/*.xml</param-value>
  22.    </context-param>
  23.  
  24.    <listener>
  25.       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  26.    </listener>
  27.  
  28.  
  29. <!-- 配置DispatcherServlet load-on-startup要為1 它會根据contextConfigLocation生成一個spring的context-->
  30.    <servlet>
  31.       <servlet-name>spring</servlet-name>
  32.       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  33.       <init-param>
  34.          <param-name>contextConfigLocation</param-name>
  35.          <param-value>/WEB-INF/config/spring-servlet.xml</param-value>
  36.       </init-param>
  37.       <load-on-startup>1</load-on-startup>
  38.    </servlet>
  39.  
  40.    <servlet-mapping>
  41.       <servlet-name>spring</servlet-name>
  42.       <url-pattern>/</url-pattern>
  43.    </servlet-mapping>
  44.  
  45.  
  46.  
  47.  <filter>
  48.         <filter-name>encodingFilter</filter-name>
  49.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  50.         <init-param>
  51.             <param-name>encoding</param-name>
  52.             <param-value>UTF-8</param-value>
  53.         </init-param>
  54.         <init-param>
  55.             <param-name>forceEncoding</param-name>
  56.             <param-value>true</param-value>
  57.         </init-param>
  58.     </filter>
  59.     <filter-mapping>
  60.         <filter-name>encodingFilter</filter-name>
  61.         <url-pattern>/*</url-pattern>
  62.     </filter-mapping>
  63.  
  64. </web-app>

spring-servlet.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4.     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans
  6.        http://www.springframework.org/schema/beans/spring-beans.xsd
  7.        http://www.springframework.org/schema/context
  8.        http://www.springframework.org/schema/context/spring-context.xsd
  9.        http://www.springframework.org/schema/tx
  10.        http://www.springframework.org/schema/tx/spring-tx.xsd
  11.           http://www.springframework.org/schema/mvc
  12.        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  13.  
  14.     <!-- 配置扫描的包 这里配置的包和它的下级包都会被扫描 这样不仅会扫描@controller @service @repository 还会扫描@component-->
  15.     <context:component-scan base-package="com.zjf" />
  16.  
  17.  
  18.      <!-- 注册HandlerMapper、HandlerAdapter两个映射类 这是spring为@Controller分发请求所必须的 同时也是表单数据转换为对象(如xml json等)必须的-->
  19.     <mvc:annotation-driven />
  20.  
  21.  
  22.      <!-- 访问静态资源 如果没有这个配置 那么静态的js css文件将会报错 因为在web.xml中我们配置了<url-pattern>/</url-pattern> -->
  23.     <mvc:default-servlet-handler />
  24.  
  25.     <!-- 视图解析器 这里使用InternalResourceViewResolver -->
  26.     <bean
  27.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  28.         <property name="prefix" value="/WEB-INF/view/"></property>
  29.         <property name="suffix" value=".jsp"></property>
  30.     </bean>
  31.  
  32. </beans>
时间: 2024-08-25 05:25:48

Spring mvc项目的web.xml以及注释的相关文章

maven web项目的web.xml报错The markup in the document following the root element must be well-formed.

maven项目里面的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

[Solution] 如何更好的管理MVC项目的Web.Config

投石问: 很多时候在Web.Config中的配置在生产与Prod环境都是有所不同的 , 一大堆绿绿的注释,debug的设置与 pord的设置混合在一起,这个你能忍?! 那么如何更好的去管理自己项目中的 Web.Config , ok , let's moving . 问路答: 在编译发布的过程中,Microsoft Visual Studio 2010 及以下版本 会以 Web.Config为基础,而后基于编译的模式(debug or release)对 Web.Debug.Config 和 W

spring Mvc 执行原理 及 xml注解配置说明 (六)

Spring MVC 执行原理 在 Spring Mvc 访问过程里,每个请求都首先经过 许多的过滤器,经 DispatcherServlet 处理; 一个Spring MVC工程里,可以配置多个的 dispatcherServlet ,每个 DispatcherServlet 可以对应多个的 HandlerMapping ,每个 HandlerMapping 可以有自己的 Interceptor (拦截器). 1. 请求首先 由 前端 DispatcherServlet 捕获: 2. Disp

Visual Studio 中用于 ASP.NET Web 项目的 Web 服务器

Visual Studio 中用于 ASP.NET Web 项目的 Web 服务器 当您在 Visual Studio 中开发 Web 项目时,需要 Web 服务器才能测试或运行它们.             利用 Visual Studio,您可以使用不同的 Web 服务器进行测试,包括 IIS Express.Internet Information Services (IIS).外部主机或自定义 Web 服务器.  您可以将其中任何一种 Web 服务器用于基于文件的 Web 应用程序项目.

如何修改MyEclipse项目的web context-root

修改一个MyEclipse项目的名称很容易,右键点项目->rename就行了. 但此时项目的web context-root 还没有改变,需要右键点项目->properties->MyEclipse->Web->Web context-root,修改成你想要的新名,点OK就可以了. 细节如下图. 2016年8月23日11:29:58

springMVC+Mybatis的maven-web项目的pom.xml文件内容

pom.xml文件内容 1 <!-- 第一行是XML头,指定了该xml文档的版本和编码方式 --> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://m

对于maven创建spark项目的pom.xml配置文件(图文详解)

不多说,直接上干货! http://mvnrepository.com/ 这里,怎么创建,见 这里, 我重点说下spark项目,因为,对于hadoop这样的,我已经写了大量博客了. 比如,我目前用得较多的spark-mllib. 这里spark-mllib_2.10 就是你的scala版本是2.10.X系列.比如我一般是使用scala-2.10.4. 这里spark-mllib_2.11 就是你的scala版本是2.11.X系列. 同时,大家要养成规范,http://mvnrepository.

[转]基于Spring + Spring MVC + Mybatis 高性能web构建

http://blog.csdn.net/zoutongyuan/article/details/41379851/ 一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.AngularJs,做了大量的研究,对前后端交互有了更深层次的认识. 今天抽个时间写这篇文章,我有预感,这将是一篇很详细的文章,详细的配置,详细的注释,看起来应该很容易懂. 用最合适的技术去实现,并不断追求最佳实践.这就是架构之道. 希望这篇文章能给你们带来一些帮助,同时希望你们可以为这个项目贡献你的想法. 源

基于Spring + Spring MVC + Mybatis 高性能web构建

一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.AngularJs,做了大量的研究,对前后端交互有了更深层次的认识. 今天抽个时间写这篇文章,我有预感,这将是一篇很详细的文章,详细的配置,详细的注释,看起来应该很容易懂. 用最合适的技术去实现,并不断追求最佳实践.这就是架构之道. 希望这篇文章能给你们带来一些帮助,同时希望你们可以为这个项目贡献你的想法. 源码地址:https://github.com/starzou/quick4j 点击打开 看我们的项目结构: 是一个典型