SpringMVC框架配置
来源:互联网 发布:食品代加工 知乎 编辑:程序博客网 时间:2024/06/08 19:43
配置springMVC框架
环境:eclipse+Tomcat 7.0.70+JDK 1.8
架包:
该架包配置中包含了Spring架包,部分Hibernate架包,以及Junit和其他一些依赖项
Spring架包下载链接:https://repo.spring.io/webapp/#/home
配置文件目录结构:
web.xml配置
<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list><!-- 配置SpringMVC的DispatcherServlet 控制器 --><servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 配置DispatcherServlet的一个初始化参数:配置SpringMVC配置文件的位置名称 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping> <!-- 配置Spring IOC 容器Spring ApplicationContext配置文件的路径 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- Spring IOC监听器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置编码方式过滤器,在所有过滤器的前面 --><filter><filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 使用SpringMVC框架实现REST风格,配置 HiddenHttpMethodFilter --><filter><filter-name>hiddenHttpMethodFilter</filter-name><filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class></filter><filter-mapping><filter-name>hiddenHttpMethodFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!-- 注解配置 --><context:annotation-config /><!-- 扫描装配bean --><context:component-scan base-package="com.osms" /><!-- 配置自动扫描的包 --><context:component-scan base-package="com.osms" use-default-filters="false"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /><context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /></context:component-scan></beans>
springmvc.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><!-- 配置自动扫描的包 --><context:component-scan base-package="com.osms" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/><context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/></context:component-scan><!-- 配置视图解析器:把handler方法返回值解析为实际的物理视图 --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/views/"></property><property name="suffix" value=".jsp"></property> </bean><!-- 配置静态资源:default-servlet-handler将在SpringMVC上下文中定义DefaultServletHttpRequestHandler, 它会对进入DispatcherServlet的请求进行帅选,如果发现是没有经过映射的请求,就将该请求交由WEB应用服务器默认的 Servlet处理。如果不是静态资源的请求,才由DispatcherServlet继续处理。 --><mvc:default-servlet-handler /><!-- 配置开启注解 --><mvc:annotation-driven/></beans>
tag:项目配置源码,若有需求将会贴出;也许各位自己配置的框架会报错,那是个版本之间的兼容问题,换对版本即可。
0 0
- springMVC配置框架
- springmvc框架配置
- SpringMVC框架配置流程
- SpringMVC框架配置
- 关于SpringMVC框架配置搭建
- Springmvc框架配置和详情
- springMVC框架的配置过程
- SpringMVC框架配置(未完成)
- springmvc+ibatis框架搭建(xml配置)
- SpringMVC框架搭建的几个核心配置
- JavaWeb配置详解(结合框架SpringMVC)
- SSM(Spring+SpringMVC+Mybatis)框架配置例子
- SpringMvc 框架静态资源访问配置
- SpringMVC 配置和使用校验框架
- 1. SpringMVC框架之 配置详解
- Springmvc学习(01)-框架原理 && 入门配置
- 使用Validator做SpringMVC的验证框架 - 配置SpringMVC环境
- SpringMVC框架
- 实验 利用百度地图对自己定位
- JSP 防止网页刷新重复提交数据
- javaweb srpingmvc mybatis 分页查询 增加示例 参数类型map 和实体对象
- ArrayList、LinkedList、 Vector、Map 用法比较
- 【算法】查找栈内最小值的O(1)算法————用辅助栈实现
- SpringMVC框架配置
- JVM 优点与缺点的深入分析
- Spring事务配置的五种方式
- Java servlet
- s3c2440时钟分频
- Power
- 【算法】通过辅助栈实现排序已知栈
- Linux初识软连接和硬链接
- Java 类的生命周期详解