springmvc xml 常用配置方式(拦截器,文件上传,适配器等)
来源:互联网 发布:mac系统如何关闭程序 编辑:程序博客网 时间:2024/06/06 08:46
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 可以扫描controller、service、... 这里让扫描controller,指定controller的包 --> <context:component-scan base-package="cn.ssm.controller"></context:component-scan> <!-- 静态资源解析 包括 :js、css、img、.. --> <mvc:resources location="/js/" mapping="/js/**"/> <mvc:resources location="/img/" mapping="/img/**"/> <!--注解映射器 --> <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> --> <!--注解适配器 --> <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> --> <!-- 使用 mvc:annotation-driven代替上边注解映射器和注解适配器配置 mvc:annotation-driven默认加载很多的参数绑定方法, 比如json转换解析器就默认加载了,如果使用mvc:annotation-driven不用配置上边的RequestMappingHandlerMapping和RequestMappingHandlerAdapter 实际开发时使用mvc:annotation-driven --> <mvc:annotation-driven conversion-service="conversionService" validator="validator"></mvc:annotation-driven> <!-- 视图解析器 解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置jsp路径的前缀 --> <property name="prefix" value="/WEB-INF/jsp/"/> <!-- 配置jsp路径的后缀 --> <property name="suffix" value=".jsp"/> </bean> <!-- 自定义参数绑定 --> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <!-- 转换器 --> <property name="converters"> <list> <!-- 日期类型转换 --> <bean class="cn.ssm.controller.converter.CustomDateConverter"/> </list> </property> </bean> <!-- 校验器 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <!-- hibernate校验器--> <property name="providerClass" value="org.hibernate.validator.HibernateValidator" /> <!-- 指定校验使用的资源文件,在文件中配置校验错误信息,如果不指定则默认使用classpath下的ValidationMessages.properties --> <property name="validationMessageSource" ref="messageSource" /> </bean><!-- 校验错误信息配置文件 --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <!-- 资源文件名--> <property name="basenames"> <list> <value>classpath:CustomValidationMessages</value> </list> </property> <!-- 资源文件编码格式 --> <property name="fileEncodings" value="utf-8" /> <!-- 对资源文件内容缓存时间,单位秒 --> <property name="cacheSeconds" value="120" /> </bean> <!-- 全局异常处理器 只要实现HandlerExceptionResolver接口就是全局异常处理器 --> <bean class="cn.ssm.exception.CustomExceptionResolver"></bean> <!-- 文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 设定默认编码 --> <property name="defaultEncoding" value="UTF-8"></property> <!-- 设定文件上传的最大值5MB,5*1024*1024 --> <property name="maxUploadSize" value="5242880"></property> </bean> <!--拦截器 --><mvc:interceptors> <!--多个拦截器,顺序执行 --> <!-- 登陆认证拦截器 --> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="cn.ssm.interceptor.LoginInterceptor"></bean> </mvc:interceptor> <mvc:interceptor> <!-- /**表示所有url包括子url路径 --> <mvc:mapping path="/**"/> <bean class="cn.ssm.interceptor.HandlerInterceptor1"></bean> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="cn.ssm.interceptor.HandlerInterceptor2"></bean> </mvc:interceptor></mvc:interceptors> </beans>
0 0
- springmvc xml 常用配置方式(拦截器,文件上传,适配器等)
- springmvc文件上传和拦截器
- SpringMvc文件上传、下载和拦截器
- springmvc基于xml文件的配置方式
- Struts2 文件上传拦截器配置问题
- struts2实现文件上传(配置拦截器)
- SpringMVC、SpringMVC XML配置(纯XML方式)
- springmvc 异常处理、文件上传以及拦截器相关知识
- SpringMVC文件上传拦截器,大小验证,类型验证
- springmvc配置上传文件
- SpringMVC上传文件配置
- SpringMVC文件上传配置
- springmvc 拦截器配置
- springMVC拦截器配置
- springMvc拦截器配置
- SpringMvc拦截器配置
- SpringMvc配置拦截器
- springmvc拦截器配置
- Atitit opencv3.0 3.1 3.2 新特性attilax总结
- 打印两个链表的公共值练习
- 浅谈简单工厂模式、工厂方法模式、抽象工厂模式
- Java 注解详解 (annotation)
- 80%的程序员不了解的调试技巧
- springmvc xml 常用配置方式(拦截器,文件上传,适配器等)
- LL(1)语法分析程序
- ABP入门系列(11)——编写单元测试
- 17-02-10
- React Native学习安卓手机上的返回键BackAndroid
- Linux基本命令介绍
- idea maven项目连接Oracle数据库失败
- Jenkins自动化构建集成(一)
- Atitti html5 h5 新特性attilax总结