Spring MVC全局异常实例详解

 更新时间:2018年02月19日 10:42:37   作者:芥末无疆sss  
这篇文章主要给大家介绍了关于Spring MVC全局异常的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

目录

无SpringMVC全局异常时的流程图


SpringMVC全局异常流程图

其实是一个ModelAndView对象

配置文件

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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task"  xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  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/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
 <context:component-scan base-package="com.mmall">
  <!-- 扫描controller的职责交给dispatcher-servlet.xml,所以排除 -->
  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
 </context:component-scan>
 <aop:aspectj-autoproxy/>
 <!-- spring schedule -->
 <context:property-placeholder location="classpath:datasource.properties"/>
 <task:annotation-driven/>
 <import resource="applicationContext-spring-session.xml"/>
 <import resource="applicationContext-datasource.xml"/>
</beans>

dispacher-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:aop="http://www.springframework.org/schema/aop"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">
 <!-- springmvc扫描包指定到controller,防止重复扫描 -->
 <context:component-scan base-package="com.mmall.controller" annotation-config="true" use-default-filters="false">
  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
 </context:component-scan>
 <mvc:annotation-driven>
  <mvc:message-converters>
   <bean class="org.springframework.http.converter.StringHttpMessageConverter">
    <property name="supportedMediaTypes">
     <list>
<value>text/plain;charset=UTF-8</value>
      <value>text/html;charset=UTF-8</value>
     </list>
    </property>
   </bean>
   <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes">
     <list>
      <value>application/json;charset=UTF-8</value>
     </list>
    </property>
   </bean>
  </mvc:message-converters>
 </mvc:annotation-driven>
 <mvc:interceptors>
  <!-- 定义在这里的,所有的都会拦截-->
  <mvc:interceptor>
   <!--manage/a.do /manage/*-->
   <!--manage/b.do /manage/*-->
   <!--manage/product/save.do /manage/**-->
   <!--manage/order/detail.do /manage/**-->
   <mvc:mapping path="/manage/**"/>
   <!--<mvc:exclude-mapping path="/manage/user/login.do"/>-->
   <bean class="com.mmall.controller.common.interceptor.AuthorityInterceptor" />
  </mvc:interceptor>
 </mvc:interceptors>
</beans>

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

相关文章

  • 详解SpringBoot 处理异常的几种常见姿势

    详解SpringBoot 处理异常的几种常见姿势

    这篇文章主要介绍了详解SpringBoot 处理异常的几种常见姿势,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-08-08
  • java集合Collection常用方法解读

    java集合Collection常用方法解读

    这篇文章主要介绍了java集合Collection常用方法解读,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-03-03
  • Mybatis如何通过接口实现sql执行原理解析

    Mybatis如何通过接口实现sql执行原理解析

    为了简化MyBatis的使用,MyBatis提供了接口方式自动化生成调用过程,可以大大简化MyBatis的开发,下面这篇文章主要给大家介绍了关于Mybatis如何通过接口实现sql执行原理解析的相关资料,需要的朋友可以参考下
    2023-01-01
  • SpringBoot打成jar包瘦身方法总结

    SpringBoot打成jar包瘦身方法总结

    springBoot打包的时候代码和jar包打包在同一个jar包里面,会导致jar包非常庞大,下面这篇文章主要给大家介绍了关于SpringBoot打的jar包瘦身方法的相关资料,需要的朋友可以参考下
    2022-12-12
  • Java中获取键盘输入值的三种方法介绍

    Java中获取键盘输入值的三种方法介绍

    这篇文章主要介绍了Java中获取键盘输入值的三种方法介绍,具有一定参考价值,需要的朋友可以了解下。
    2017-11-11
  • 在eclipse中修改tomcat的部署路径操作

    在eclipse中修改tomcat的部署路径操作

    这篇文章主要介绍了在eclipse中修改tomcat的部署路径操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-01-01
  • 详解SpringBoot开发案例之整合定时任务(Scheduled)

    详解SpringBoot开发案例之整合定时任务(Scheduled)

    本篇文章主要介绍了详解SpringBoot开发案例之整合定时任务(Scheduled),具有一定的参考价值,有兴趣的可以了解一下
    2017-07-07
  • 详解Java Web如何限制访问的IP的两种方法

    详解Java Web如何限制访问的IP的两种方法

    这篇文章主要介绍了详解Java Web如何限制访问的IP的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-10-10
  • Springboot-dubbo-fescar 阿里分布式事务的实现方法

    Springboot-dubbo-fescar 阿里分布式事务的实现方法

    这篇文章主要介绍了Springboot-dubbo-fescar 阿里分布式事务的实现方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-03-03
  • 基于Java多线程notify与notifyall的区别分析

    基于Java多线程notify与notifyall的区别分析

    本篇文章对Java中多线程notify与notifyall的区别进行了详细的分析介绍。需要的朋友参考下
    2013-05-05

最新评论