本文通过一个小demo给大家介绍spring AOP 实现的异常捕获和日志的方法技巧,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
之前给大家介绍过,需要的朋友点击了解下吧,这边我将给您介绍用spring AOP 实现的异常捕获和日志的小demo,我也会详细解释相关配置。
首先给大家看一下我的工程目录:
大家可以先用eclipse中新建一个maven工程,在工程中pom.xml按下面文件添加依赖:
4.0.0 com.zy AOPException war 0.0.1-SNAPSHOT AOPException Maven Webapp http://maven.apache.org aspectj aspectjrt 1.5.2 org.springframework spring-web 5.0.6.RELEASE org.springframework spring-aop 5.0.4.RELEASE org.springframework spring-context 5.0.5.RELEASE org.springframework spring-core 5.0.6.RELEASE org.springframework spring-webmvc 5.0.6.RELEASE org.aspectj aspectjweaver 1.8.13 com.fasterxml.jackson.core jackson-annotations 2.9.5 com.fasterxml.jackson.core jackson-core 2.9.5 com.fasterxml.jackson.core jackson-databind 2.9.5 com.alibaba fastjson 1.2.47 org.springframework spring-test 5.0.6.RELEASE test org.mockito mockito-core 2.18.3 test AOPException
添加完依赖后,开始配置web.xml文件,如下:
exception-test-web contextConfigLocation //这边是加载spring的配置文件 /WEB-INF/config/applicationContext.xml spring.profiles.default production encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter /* org.springframework.web.context.ContextLoaderListener springServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation //这边是加载spring的配置文件/WEB-INF/config/spring-mvc-config.xml 1 springServlet / 20
配置完web.xml后,你可开始配置spring配置文件了,也就是applicationContext.xml文件。如下:
以上就是使用spring aop 统一捕获异常和写日志的示例demo的详细内容,更多请关注0133技术站其它相关文章!