@Aspect public class RiskExceptionAspect { private static final Logger logger = LoggerFactory.getLogger(LoggerNamesConstants.RISK); @Pointcut(value = "execution(* com.xxx.risk..*.*(..))") public void pointcut(){ } @AfterThrowing(throwing = "ex", value = "pointcut()") public void logAfterThrowingRiskAllMethods(Throwable ex) { // 将ex的类型声明为Throwable,意味着对目标方法抛出的异常不加限制 // 补充日志输出 LoggerUtil.error(ex, logger, "risk execution error :{0}", ex.getMessage()); } }
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd" default-autowire="byName"> <context:annotation-config/> <context:component-scan base-package="xxx"/> <aop:aspectj-autoproxy/>
<!--风险 异常日志切面--> <bean id="riskExceptionAspect" class="com.xxx.aspect.RiskExceptionAspect"/>