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>

总结

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

相关文章

  • Kotlin传递可变长参数给Java可变参数实例代码

    Kotlin传递可变长参数给Java可变参数实例代码

    这篇文章主要介绍了Kotlin传递可变长参数给Java可变参数实例代码,小编觉得还是挺不错的,具有一定借鉴价值,需要的朋友可以参考下
    2018-01-01
  • 基于SpringMVC实现网页登录拦截

    基于SpringMVC实现网页登录拦截

    SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理。因此,本文将为大家介绍如何通过SpringMVC实现网页登录拦截功能,需要的小伙伴可以了解一下
    2021-12-12
  • java 正则表达式获取两个字符中间的字符串方法

    java 正则表达式获取两个字符中间的字符串方法

    今天小编就为大家分享一篇java 正则表达式获取两个字符中间的字符串方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-07-07
  • Java中switch判断语句典型使用实例

    Java中switch判断语句典型使用实例

    这篇文章主要介绍了Java中switch判断语句典型使用实例,本文直接给出代码实例,在忘记switch语法时特别有用,复制修改即可使用,需要的朋友可以参考下
    2015-06-06
  • spring boot环境抽象的实现方法

    spring boot环境抽象的实现方法

    在实际开发中,开发人员在编写springboot的时候通常要在本地环境测试然后再部署到Production环境,这两种环境一般来讲是不同的,最主要的区别就是数据源的不同。本文主要介绍了这两种,感兴趣的可以了解一下
    2019-04-04
  • Java新手环境搭建 Tomcat安装配置教程

    Java新手环境搭建 Tomcat安装配置教程

    这篇文章主要为大家详细介绍了Java新手环境搭建的相关资料,Tomcat安装配置教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03
  • springboot数据库操作图文教程

    springboot数据库操作图文教程

    本文以图文并茂的形式给大家介绍了springboot数据库操作,感兴趣的朋友一起看看吧
    2017-07-07
  • java如何读取properties文件将参数值配置到静态变量

    java如何读取properties文件将参数值配置到静态变量

    这篇文章主要介绍了java如何读取properties文件将参数值配置到静态变量问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • JDBC 程序的常见错误及调试方法

    JDBC 程序的常见错误及调试方法

    本文是《Java Web开发教程——入门与提高篇(JSP+Servlet)》一书《第9章 JDBC技术》的补充内容。
    2009-06-06
  • 用Java实现一个静态链表的方法步骤

    用Java实现一个静态链表的方法步骤

    这篇文章主要介绍了用Java实现一个静态链表的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-02-02

最新评论