Technology
May 17, 2016
Aspect-Oriented Programming in Spring Boot Part 3: Setting up AspectJ Load-Time Weaving

This is the final part in a three-part series on aspect-oriented programming (AOP) with Spring Boot, which covers how to set up AspectJ load-time weaving (LTW). Part one covers how to make your own aspect, and part two details the differences between using Spring for AOP and using AspectJ.
Getting AspectJ load-time weaving working in Spring Boot can be a tricky proposition. Unlike Spring proxies, which Spring Boot uses to support AOP out of the box using the spring-boot-starter-aop dependency (mvnrepository link), AspectJ requires additional configuration across several areas. There are four main components: adding AspectJ-specific configuration, configuring Spring Boot to recognize AspectJ, setting up dependencies, and passing the correct JVM arguments whenever the code executes.
Note that while the spring-aop-aspectj-ltw sample project sets the Java property “spring.aop.proxy-target-class” to true to force Spring proxies to use CGLIB, CGLIB isn’t actually required for Spring to use AspectJ. This was only done so concrete classes that have interfaces can be directly injected with @Autowired for testing purposes to demonstrate how AspectJ behaves under different scenarios (which are covered in part two).
AspectJ Configuration Via aop.xml
The @Aspect, @Around, and other AOP annotations
