Spring MVC +Mybatis + Maven 配置之Spring-Servlet配置

       Spring-Servlet.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/util 
            http://www.springframework.org/schema/util/spring-util-3.1.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.1.xsd">
        <mvc:default-servlet-handler />
        <mvc:annotation-driven>
            <mvc:message-converters>
                <!--定义接收的消息编码格式为utf-8-->
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>

                <!-- 启动JSON格式的配置 -->
                <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <!-- ajax方式提交的请求,不能为 *.html格式,换成*.json格式就可以了 -->
                    <property name="supportedMediaTypes">
                        <list>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>

        <!--使用JstlView作为缺省的view来渲染结果-->
        <bean name="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass">
                <value>org.springframework.web.servlet.view.JstlView</value>
            </property>
            <property name="prefix">
                <value>/WEB-INF/jsp/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>

        <!--定义统一异常处理-->
        <bean name="exceptionResolver"  class="com.rrtong.frame.exception.RrtongMappingExceptionResolver">
            <!-- 定义异常处理页面用来获取异常信息的变量名,默认名为exception -->
            <property name="exceptionAttribute" value="ex"></property>
            <!--定义需要特殊处理的异常,用类名或完全路径名作为key,异常也页名作为值-->
            <property name="exceptionMappings">
                <props>
                    <prop key="com.rrtong.frame.exception.GuideTestException">../../exception/error-interface</prop>
                    <!--<prop key="com.rrtong.frame.exception.NotLoginException">login</prop>-->
                    <prop key="java.lang.Exception">../../exception/errorPage</prop>
                </props>
            </property>
            <property name="statusCodes">     
                <props>     
                    <prop key="errors/error">500</prop>     
                    <prop key="errors/404">404</prop>     
                </props>     
            </property>           
            <!-- 设置日志输出级别,不定义则默认不输出警告等错误日志信息 -->
            <property name="warnLogCategory" value="WARN" />
            <!-- 默认HTTP状态码 -->
            <property name="defaultStatusCode" value="500" />
        </bean>

        <!-- 配置springMVC不拦截静态资源,允许直接访问-->
        <mvc:resources location="/plugins/" mapping="/plugins/**" />
        <mvc:resources location="/error/" mapping="/error/**" />
        <mvc:resources location="/js/" mapping="/js/**" />
        <mvc:resources location="/app/" mapping="/app/**" />
        <mvc:resources location="/jslibs/" mapping="/jslibs/**" />
        <mvc:resources location="/scripts/" mapping="/scripts/**" />
        <mvc:resources location="/images/" mapping="/images/**" />
        <mvc:resources location="/css/" mapping="/css/**" />
        <mvc:resources location="/" mapping="/*.ico" />
        
        <!--定义无需登录验证的页面拦截器-->
        <mvc:interceptors>          
            <mvc:interceptor>              
               <mvc:mapping path="/bp/*.do" />
               <mvc:mapping path="/bs/*.do" />
               <mvc:mapping path="/person/*.do" />
               <bean class="com.rrtong.interceptors.SecurityInterceptor">              
                   <property name="excludedUrls">                  
                       <list>                    
                           <value>/login.do</value>                    
                           <value>/auth.do</value>                      
                       </list>                
                   </property>                         
               </bean>          
           </mvc:interceptor>       
        </mvc:interceptors>

       <!-- 根据请求的参数确定调用的方法 -->
       <bean id="parameterMethodNameResolver"class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
           <property name="paramName" value="method"></property>
           <property name="defaultMethodName" value="index"></property>
       </bean>

       <!-- 国际化资源文件绑定,该文件放置在src下--> 
       <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
           <property name="basename" value="error_code"></property> 
           <property name="defaultEncoding" value="UTF-8"></property> 
       </bean>
    
       <!--定义上传文件大小限制-->     
       <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">        
           <property name="maxUploadSize" value="2200000"/>
           <property name="defaultEncoding"> 
               <value>UTF-8</value> 
           </property> 
      </bean>

    <!-- 验证码配置 -->
    <bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
        <property name="config">
            <bean class="com.google.code.kaptcha.util.Config">
                <constructor-arg type="java.util.Properties">
                    <value>
                    kaptcha.border=no
                    kaptcha.textproducer.char.space=3
                    kaptcha.textproducer.char.string=235689
                    kaptcha.noise.color=yellow
                    kaptcha.image.width=80
                    kaptcha.image.height=25
                    kaptcha.textproducer.font.size=15
                    kaptcha.noise.impl=com.google.code.kaptcha.impl.NoNoise
                    kaptcha.textproducer.font.names=Courier, Arial 
                    kaptcha.obscurificator.impl=com.google.code.kaptcha.impl.ShadowGimpy
                    </value>
                </constructor-arg>
            </bean>
        </property>
    </bean>

    <!--aop配置-->
    <!-- 定义通知advice -->
    <bean id="guideIntegralAfterAdvice" class="com.rrtong.interceptors.GuideIntegralAfterAdvice" />
    <!-- 定义pointcut和通知者advisor的联合切入点和通知者 -->
    <bean id="addGuideIntegralAfterTesting" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <!-- 引用通知接口的实现类 -->
           <property name="advice" ref="guideIntegralAfterAdvice" />
        <!-- 正则表达式匹切入点方法名 -->
          <property name="patterns">
               <list>
                <value>.*insertTestStudent</value>
               </list>
          </property>
     </bean>
     
     <!-- 定义自动代理 -->
      <bean id="addIntegralAutoProxyAop" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
          <property name="beanNames">
              <list>
                  <value>*Service*</value>
              </list>
          </property>
  
          <property name="interceptorNames">
               <list>
                <value>addIntegralAfterOperating</value>
               </list>
          </property>
     </bean>      
  </beans>
 
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值