spring-servlet.xml简单示例

spring-servlet.xml简单示例

某个项目中的spring-servlet.xml 记下来以后研究用

 <!-- springMVC简单配置 -->
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
"> <mvc:annotation-driven />
<aop:aspectj-autoproxy /> <!-- 自动扫描并注入 -->
<context:component-scan base-package="net.crm" ></context:component-scan> <!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为1MB -->
<property name="maxUploadSize">
<value>101048576</value>
</property>
</bean> <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
<!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/page/500.jsp页面 -->
<prop
key="org.springframework.web.multipart.MaxUploadSizeExceededException">500</prop>
</props>
</property>
</bean> <!-- 对静态资源的访问 -->
<mvc:resources location="/" mapping="/**/*.html"/>
<mvc:resources location="/font/" mapping="/font/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/javascripts/" mapping="/javascripts/**"/>
<mvc:resources location="/stylesheets/" mapping="/stylesheets/**"/> <!-- 个人登录过滤器 -->
<mvc:interceptors>
<!-- 拦截器 -->
<mvc:interceptor>
<mvc:mapping path="/user/**"/>
<mvc:mapping path="/role/**"/>
<mvc:mapping path="/systerm/**"/>
<mvc:mapping path="/manage/**"/>
<mvc:mapping path="/customer/**"/>
<mvc:mapping path="/resume/**"/>
<bean class="net.crm.base.interceptor.UserLoginInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/user/**"/>
<mvc:mapping path="/role/**"/>
<mvc:mapping path="/systerm/**"/>
<mvc:mapping path="/manage/**"/>
<mvc:mapping path="/customer/**"/>
<mvc:mapping path="/resume/**"/>
<bean class="net.crm.base.interceptor.RoleInterceptor"></bean>
</mvc:interceptor> </mvc:interceptors> <bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> -->
<property name="prefix" value="/WEB-INF/page/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean> <!-- 从这行往下是要添加的 -->
<context:annotation-config />
<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="true">
<dwr:config-param name="allowScriptTagRemoting"
value="true" />
<dwr:config-param name="crossDomainSessionSecurity"
value="false" />
</dwr:controller>
<beans:bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<beans:property name="order" value="1" />
</beans:bean>
<beans:bean
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<beans:property name="order" value="2" />
</beans:bean>
<!--添加结束--> </beans>

第二个

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.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"> <!-- 拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 拦截类型 -->
<mvc:mapping path="/**" />
<!-- 排除拦截的内容 -->
<mvc:exclude-mapping path="/login" />
<mvc:exclude-mapping path="/register" />
<mvc:exclude-mapping path="/verifycode" />
<mvc:exclude-mapping path="/js/**" />
<mvc:exclude-mapping path="/css/**" />
<mvc:exclude-mapping path="/layer/**" />
<mvc:exclude-mapping path="/style/**" />
<bean
class="com.jieyou.login_register.AuthorityInterceptor.AuthorityInterceptor" />
</mvc:interceptor>
</mvc:interceptors> <!-- 默认首页 -->
<mvc:view-controller path="/" view-name="redirect:/login" /> <!-- 用于支持Servlet、JSP视图解析 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 表示JSP模板页面需要使用JSTL标签库,classpath中必须包含jstl的相关jar包 -->
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<!-- 查找视图页面的前缀和后缀 -->
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean> <!-- 对静态资源文件的访问 -->
<mvc:resources location="/css/" mapping="/css/**"
cache-period="31556926" />
<mvc:resources location="/js/" mapping="/js/**"
cache-period="31556926" />
<mvc:resources location="/style/" mapping="/style/**"
cache-period="31556926" /> <mvc:default-servlet-handler /> </beans>
上一篇:Event事件跨浏览器封装


下一篇:ASP.NET API Helper Page 创建并生成相关帮助文档