Could someone provide a sample code snippet that stitches two java interfaces using spring-aop introduction (mixin)?
I'm looking for AspectJ annotation style configuration. Also, the specific use case I have is to stitch a few java beans each implementing their own interfaces together. So, rather than having a delegate coded, if I could just get away by using Spring XML, it'd be awesome.
You can use @DeclareParents or <aop:declare-parents> to get the mixin behavior. For example,
@DeclareParents(value="service.*", defaultImpl=AuditRecorderDefaultImpl.class)
private AuditRecorder mixin;
will mixin all classes in the service package with the AuditRecorder interface automatically forwarding each method to AuditRecorderDefaultImpl.
You can see working examples of this from AspectJ in Action's downloadable sources. You can also see detailed explanation in Spring documentation.
A demo based on Spring in Action book 4th edition is here, the configuration is JavaConfig style with @ComponentScan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With