Spring Boot aop使用指南
2021-05-12 08:30
阅读:677
标签:ann ota 指南 throw before aop targe oid tar
1. 使用示例
1.在pom中添加依赖
org.springframework.boot
spring-boot-starter-aop
2.使用aop注解
public class Test{
public static void main(String[] args) {
ApplicationContext ac = (ApplicationContext) new AnnotationConfigApplicationContext(Cfg.class);
Target target = (Target) ac.getBean("target");
target.print();
}
}
@Configuration
@ComponentScan("com.example.springboot")
class Cfg{
}
@Component
class Target{
public void print(){
System.out.println("target print");
}
}
@Aspect
@Component // 必须纳入容器管理
class MyAspect{
@Before("execution(* com.example.springboot.Target.print())")
public void before(){
System.out.println("before print");
}
}
2. 增强类型
@Before
@AfterReturning
@AfterThrowing
@After // 其实是AfterFinally增强
@Around // 环绕增强
Spring Boot aop使用指南
标签:ann ota 指南 throw before aop targe oid tar
原文地址:https://www.cnblogs.com/memo20/p/13140593.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:Spring Boot aop使用指南
文章链接:http://soscw.com/index.php/essay/84614.html
文章标题:Spring Boot aop使用指南
文章链接:http://soscw.com/index.php/essay/84614.html
评论
亲,登录后才可以留言!