You can only claim you know Spring if you fully understand the Proxy design pattern and how the framework uses it to do its magic. Join this live coding session to explore 6 ways of intercepting method calls that you can use to cast your own spells and dramatically simplify your codebase.
Grab a strong coffee and prepare yourself for a whirlwind of **live-coding**, interwoven with **deep theoretical concepts and implementation details** that you need to master if you are using the Spring Framework. We’ll start from a Decorator pattern implementation, proving 2 ways to wire it with Spring, then move to bare-hands interface proxies, concrete classes proxies, @Aspect applied to custom annotations, plus some standard off-the-shelf Spring aspects.
Join this talk and learn real-world best practices to use with Aspects, design hints, under-the-hood implementation details, debugging tips, and performance impact of aspects. All in an interactive, entertaining, and extremely dynamic session.
SpotFlow: Tracking Method Calls and States at Runtime
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
1. victorrentea@gmail.com ♦ ♦ @victorrentea ♦ VictorRentea.ro
All the code is available on the branch JAX_Mainz on https://github.com/victorrentea/spring
2. Victor Rentea
VictorRentea.ro
Blog, Best Talks, Video Courses, ...
Independent Trainer
for companies and individuals
Founder of
Bucharest Software Craftsmanship Community
Java Champion
❤️ Simple Design, Refactoring, Unit Testing ❤️
3. Technical Training
400 days
(100+ online)
2000 devs
8 years
More: VictorRentea.ro
Workshops: victorrentea.teachable.com
50 companies
Reach out
to me:
Hibernate
Spring Functional Prog
Java Performance
Reactive Prog
Design Patterns
Pragmatic DDD
Clean Code
Refactoring
Unit Testing
TDD
any
lang
@victorrentea
Intense
12. @ Victo
r
Rentea
42
•A method of a non-Spring bean?
• Think new
•A final method/class?
• For a class-proxy:
•A static method?
•Field access?
•A local method call?
Can Spring AOP Intercept…
NO!
NO!
Spring AOP can only intercept method calls
NO!
Well…
Actually…
You know…
You can do any of that via:
Bytecode Enhancement
(compile-time hacking)
Or Instrumentation
(classload-time hacking)
NO!!!
NO!
How could it be overridden?
https://github.com/dsyer/spring-boot-aspectj#
13. @VictorRentea
43
proxy
methodWithTx();
myselfProxied.methodWithTx();
War Stories
@Transactional(propagation = REQUIRES_NEW)
public void methodWithTx() {
@Autowired
private CurrentClass myselfProxied;
--or–
move methodWithTx() to another @Autowired bean
--or--
CurrentClass myselfProxied =
(CurrentClass)AopContext.currentProxy();
--or--
transactionTemplate.execute(s->methodWithTx());
https://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-method-within-the-same-class-does-not-wo
23. @VictorRentea
53
Custom Aspects - Best Practices
"execution(* com.mycomp.proj.facade.*.*(..))"
is less magic than
package names
or
class name patterns
"execution(* com.mycomp..*DAO.*(..))"
annotation-based weaving
26. find me on Twitter: @victorrentea
Company Training:
victorrentea@gmail.com
Training for You:
victorrentea.teachable.com
Blog, Talks, Curricula:
victorrentea.ro