Aop之 agent 增强
承接上篇文章,本篇讲述Aop的agent增强方式。运行时虚拟机参数设置。
·
承接上篇文章,本篇讲述Aop的agent增强方式
@Aspect
public class MyAspect {
@Before("execution(* com.shuttle.spring5.service.MyService.*())")
public void before() {
System.out.println("before service...");
}
}
@Service
public class MyService {
public void service1() {
System.out.println("service1...");
hello();
}
public void hello() {
System.out.println("hello...");
}
}
@SpringBootApplication
public class A10Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(A10Application.class);
MyService service = context.getBean(MyService.class);
System.out.println("service class: " + service.getClass());
service.service1();
}
}
运行时虚拟机参数设置
-javaagent:C:\Users\123\.m2\repository/org/aspectj/aspectjweaver/1.9.4/aspectjweaver-1.9.4.jar
程序运行结果如下:
service class: class com.shuttle.spring5.service.MyService
before service…
service1…before service…
hello…
类加载增强class文件【截取自课程视频】:
更多推荐
所有评论(0)