Spring Boot AOP Tutorial 发表于 2018-05-12 | 分类于 Server , SpringBoot , AOP 定义计算执行时间1234567891011121314@Aspect@Componentclass ExecutedTimeAop { private val logger = LoggerFactory.getLogger(ExecutedTimeAop::class.java) @Around("execution(* com.six.god..create(..))") @Throws(Throwable::class) fun run(joinPoint: ProceedingJoinPoint): Any? { var result: Any? = null val timeMillis = measureTimeMillis { result = joinPoint.proceed() } return result }} 作用于com.six.god下所有名字为create()的方法 配合注解使用定义注解 12345@Target(AnnotationTarget.FUNCTION)@Retention(AnnotationRetention.RUNTIME)@Inherited@MustBeDocumentedannotation class ExecutedTime 定义AOP 1234567891011121314@Aspect@Componentclass ExecutedTimeAop { private val logger = LoggerFactory.getLogger(ExecutedTimeAop::class.java) @Around(value = "@annotation(ExecutedTime)") @Throws(Throwable::class) fun run(joinPoint: ProceedingJoinPoint): Any? { var result: Any? = null val timeMillis = measureTimeMillis { result = joinPoint.proceed() } return result }}