aop注解在整个类生效

简介: aop注解在整个类生效

志向是天才的幼苗,经过热爱劳动的双手培育,在肥田沃土里将成长为粗壮的大树。——苏霍姆林斯基

之前写过自定义注解和AOP,但其是作用于方法上

今天用kotlin写一个作用在类上的:主要是@annotation换成@within

package com.ruben.simpleboot
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class SimpleBootApplication
fun main(args: Array<String>) {
    runApplication<SimpleBootApplication>(*args)
}
// 一个简单的Controller
@RestController
@TestInterface
class TestController {
    @GetMapping("test")
    fun test(): String {
        return "test";
    }
    @GetMapping("mock")
    fun mock(): String {
        return "mock";
    }
}
// 注解
annotation class TestInterface
// AOP
@Aspect
@Component
class TestAop {
    // 针对注解目标的Class进行匹配
    @Around("@within(TestInterface)")
    fun recordWithMe(point: ProceedingJoinPoint): Any {
        return point.proceed()
    }
}


访问testmock接口均成功进入AOP逻辑

相关文章
|
5月前
|
Java 编译器 数据安全/隐私保护
自定义注解与AOP结合使用
自定义注解与AOP结合使用
59 0
|
6月前
|
Java 数据库连接 数据库
MyBatis与Spring集成&常用注解以及AOP和PageHelper分页插件整合
MyBatis与Spring集成&常用注解以及AOP和PageHelper分页插件整合
53 0
|
6月前
|
Java Spring
11Spring - 基于AspectJ的AOP开发(注解的方式)
11Spring - 基于AspectJ的AOP开发(注解的方式)
26 0
|
6月前
|
Java Spring
【注解】Spring AOP 面向切面编程之@Around的详细用法
【注解】Spring AOP 面向切面编程之@Around的详细用法
315 0
|
6月前
|
XML SQL Java
基于注解的AOP~
基于注解的AOP~
基于注解的AOP~
|
7月前
|
XML 监控 Java
注解IOC&AOP
扫描类下的注解,哪些包下的类需要使用IOC注解
66 0
|
5天前
|
缓存 Java Sentinel
Springboot 中使用 Redisson+AOP+自定义注解 实现访问限流与黑名单拦截
Springboot 中使用 Redisson+AOP+自定义注解 实现访问限流与黑名单拦截
|
5天前
|
存储 消息中间件 Java
Java多线程实战-异步操作日志记录解决方案(AOP+注解+多线程)
Java多线程实战-异步操作日志记录解决方案(AOP+注解+多线程)
|
18天前
|
Java Spring
代码优雅的转变:基于注解的AOP编程在Spring中的实践
代码优雅的转变:基于注解的AOP编程在Spring中的实践
17 0
|
21天前
|
存储 关系型数据库 MySQL
【mybatis-plus】Springboot+AOP+自定义注解实现多数据源操作(数据源信息存在数据库)
【mybatis-plus】Springboot+AOP+自定义注解实现多数据源操作(数据源信息存在数据库)