使用spring aop 统一捕获异常和写日志的示例demo

本文通过一个小demo给大家介绍spring AOP 实现的异常捕获和日志的方法技巧,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

之前给大家介绍过,需要的朋友点击了解下吧,这边我将给您介绍用spring AOP 实现的异常捕获和日志的小demo,我也会详细解释相关配置。

首先给大家看一下我的工程目录:

大家可以先用eclipse中新建一个maven工程,在工程中pom.xml按下面文件添加依赖:

  4.0.0com.zyAOPExceptionwar0.0.1-SNAPSHOTAOPException Maven Webapphttp://maven.apache.org  aspectjaspectjrt1.5.2 org.springframeworkspring-web5.0.6.RELEASE org.springframeworkspring-aop5.0.4.RELEASE org.springframeworkspring-context5.0.5.RELEASE org.springframeworkspring-core5.0.6.RELEASE org.springframeworkspring-webmvc5.0.6.RELEASE org.aspectjaspectjweaver1.8.13 com.fasterxml.jackson.corejackson-annotations2.9.5 com.fasterxml.jackson.corejackson-core2.9.5 com.fasterxml.jackson.corejackson-databind2.9.5 com.alibabafastjson1.2.47 org.springframeworkspring-test5.0.6.RELEASEtest org.mockitomockito-core2.18.3test AOPException

添加完依赖后,开始配置web.xml文件,如下:

   exception-test-web contextConfigLocation//这边是加载spring的配置文件 /WEB-INF/config/applicationContext.xml  spring.profiles.defaultproduction encodingFilterorg.springframework.web.filter.CharacterEncodingFilter encodingUTF-8 forceEncodingtrue encodingFilter/* org.springframework.web.context.ContextLoaderListener springServletorg.springframework.web.servlet.DispatcherServlet contextConfigLocation //这边是加载spring的配置文件 /WEB-INF/config/spring-mvc-config.xml1 springServlet/ 20

配置完web.xml后,你可开始配置spring配置文件了,也就是applicationContext.xml文件。如下:

  以上就是使用spring aop 统一捕获异常和写日志的示例demo的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java