SPRING MVC 的 配置 包括 包扫描 视图解析器 文件上传解析器 拦截器等
来源:互联网 发布:js prompt不弹出窗口 编辑:程序博客网 时间:2024/04/29 18:02
<?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"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- 启用spring mvc 注解-->
<mvc:annotation-driven>
<!-- 启动JSON格式的配置 -->
<mvc:message-converters>
<!-- 这里也可以自己定制class -->
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value> <!-- 避免IE出现下载JSON文件的情况 -->
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 对静态资源文件的访问 缓存一年
<mvc:resources mapping="/images/**" location="/WEB-INF/images/" cache-period="31536000"/>
<mvc:resources mapping="/css/**" location="/WEB-INF/css/" />
<mvc:resources mapping="/js/**" location="/WEB-INF/js/" />
<mvc:resources mapping="/fonts/**" location="/WEB-INF/fonts/" />
<mvc:resources mapping="/favicon.ico" location="favicon.ico" />
-->
<!-- 自动扫描的包名 ,使Spring支持自动检测组件,如注解的Controller-->
<context:component-scan base-package="com.crm.controller" />
<context:component-scan base-package="com.crm.service"/>
<!-- 视图解析器:定义跳转的文件的前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" /> <!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
</bean>
<!-- 文件上传解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>
<!--<mvc:view-controller path="/" view-name="forward:/index.jsp"/> -->
<!-- 缓存配置(两种) -->
<!-- 启用缓存注解功能(请将其配置在Spring主配置文件中) -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- Spring自己的基于java.util.concurrent.ConcurrentHashMap实现的缓存管理器(该功能是从Spring3.1开始提供的) -->
<!--
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean name="myCache" class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"/>
</set>
</property>
</bean>
-->
<!-- 若只想使用Spring自身提供的缓存器,则注释掉下面的两个关于Ehcache配置的bean,并启用上面的SimpleCacheManager即可 -->
<!-- Spring提供的基于的Ehcache实现的缓存管理器 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
<!--配置拦截器, 多个拦截器,顺序执行 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 当设置多个拦截器时,先按顺序调用preHandle方法,然后逆序调用每个拦截器的postHandle和afterCompletion方法 -->
<!--
/**的意思是所有文件夹及里面的子文件夹
/*是所有文件夹,不含子文件夹
/是web项目的根目录
exclude-mapping 不拦截的url
-->
<mvc:mapping path="/" />
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/code"/>
<mvc:exclude-mapping path="/logout"/>
<bean class="com.crm.interceptor.CommonInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**"></mvc:mapping>
<mvc:exclude-mapping path="/code"/>
<mvc:exclude-mapping path="/logout"/>
<mvc:exclude-mapping path="/login"/>
<bean class="com.crm.controller.MyInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
<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"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- 启用spring mvc 注解-->
<mvc:annotation-driven>
<!-- 启动JSON格式的配置 -->
<mvc:message-converters>
<!-- 这里也可以自己定制class -->
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value> <!-- 避免IE出现下载JSON文件的情况 -->
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 对静态资源文件的访问 缓存一年
<mvc:resources mapping="/images/**" location="/WEB-INF/images/" cache-period="31536000"/>
<mvc:resources mapping="/css/**" location="/WEB-INF/css/" />
<mvc:resources mapping="/js/**" location="/WEB-INF/js/" />
<mvc:resources mapping="/fonts/**" location="/WEB-INF/fonts/" />
<mvc:resources mapping="/favicon.ico" location="favicon.ico" />
-->
<!-- 自动扫描的包名 ,使Spring支持自动检测组件,如注解的Controller-->
<context:component-scan base-package="com.crm.controller" />
<context:component-scan base-package="com.crm.service"/>
<!-- 视图解析器:定义跳转的文件的前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" /> <!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
</bean>
<!-- 文件上传解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>
<!--<mvc:view-controller path="/" view-name="forward:/index.jsp"/> -->
<!-- 缓存配置(两种) -->
<!-- 启用缓存注解功能(请将其配置在Spring主配置文件中) -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- Spring自己的基于java.util.concurrent.ConcurrentHashMap实现的缓存管理器(该功能是从Spring3.1开始提供的) -->
<!--
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean name="myCache" class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"/>
</set>
</property>
</bean>
-->
<!-- 若只想使用Spring自身提供的缓存器,则注释掉下面的两个关于Ehcache配置的bean,并启用上面的SimpleCacheManager即可 -->
<!-- Spring提供的基于的Ehcache实现的缓存管理器 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
<!--配置拦截器, 多个拦截器,顺序执行 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 当设置多个拦截器时,先按顺序调用preHandle方法,然后逆序调用每个拦截器的postHandle和afterCompletion方法 -->
<!--
/**的意思是所有文件夹及里面的子文件夹
/*是所有文件夹,不含子文件夹
/是web项目的根目录
exclude-mapping 不拦截的url
-->
<mvc:mapping path="/" />
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/code"/>
<mvc:exclude-mapping path="/logout"/>
<bean class="com.crm.interceptor.CommonInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**"></mvc:mapping>
<mvc:exclude-mapping path="/code"/>
<mvc:exclude-mapping path="/logout"/>
<mvc:exclude-mapping path="/login"/>
<bean class="com.crm.controller.MyInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
0 0
- SPRING MVC 的 配置 包括 包扫描 视图解析器 文件上传解析器 拦截器等
- SPRING MVC 的 配置 包括 包扫描 视图解析器 文件上传解析器 拦截器等
- Spring MVC配置多视图解析器
- 基于XML配置的Spring MVC(所需jar包,web.xml配置,处理器配置,视图解析器配置)
- Spring MVC视图解析器:配置多个视图解析器的优先级
- Spring MVC视图解析器:配置多个视图解析器的优先级
- Spring mvc视图解析器
- spring-mvc视图解析器
- spring MVC视图解析器
- 【spring】spring MVC视图解析器
- Spring MVC配置多个视图解析器(FreeMarker,JSP)
- Spring MVC 多个视图解析器配置
- spring MVC自定义拦截器解析
- Spring MVC 文件上传+拦截器
- Spring MVC 之 视图解析器ResourceBundleViewResolver
- Spring MVC中的视图解析器
- Spring MVC 视图解析器(ViewResolver )
- Spring MVC视图解析器方式
- pyspider 爬虫 快速入门 |框架安装配置
- iOS UIDatePicker 的 用法
- Mysql 异常处理--condition和handler
- Kafka副本同步机制理解
- 总结-台湾项目
- SPRING MVC 的 配置 包括 包扫描 视图解析器 文件上传解析器 拦截器等
- mnist——prototxt
- Maven打包java代码目录下的属性文件
- Nhibernate的SessionContext
- 读源码:PopupWindow
- Chrome的自动代理
- java虚拟机-内存分配与回收策略
- JAVA(十三)java面向对象7-多态
- java WEB项目中的异常处理(好文章链接)