java - Creating a pointcut for all the classes in package? -
i have create configurable pointcut. can achieving dynamic pointcut.
dynamicpointcut.class
public class dynamicpointcut extends dynamicmethodmatcherpointcut { @value("${custom.logging.basepackage}") string basepackage; @override public classfilter getclassfilter() { return new classfilter() { @override public boolean matches(class<?> clazz) { list<class<?>> classlist = classfinder.find(basepackage); return classlist.stream().anymatch(x -> x.equals(clazz)); } }; } @override public boolean matches(method method, class<?> targetclass, object... args) { if(args.length>0){ return true; } return false; } }
configurableadvisorconfig.class
@configuration public class configurableadvisorconfig { @autowired private proxyfactorybean proxyfactorybean; @autowired defaultpointcutadvisor defaultpointcutadvisor; dynamicpointcut pointcut = new dynamicpointcut(); nonproductionloggingaspect advice = new nonproductionloggingaspect(); string[] advisor; list<advisor> advisorlist = new arraylist<advisor>(); @bean public string[] defaultpointcutadvisor(){ defaultpointcutadvisor.setadvice(new nonproductionloggingaspect()); defaultpointcutadvisor.setpointcut(new dynamicpointcut()); advisor = new string[]{"defaultpointcutadvisor"}; return advisor; } @bean public proxyfactorybean proxyfactorybean(){ proxyfactorybean.setinterceptornames(advisor); return proxyfactorybean; } }
you can wire aspect using static aspectof factory method (you can't see method, added aspectj compiler)
<bean class="com.youraspect" factory-method="aspectof"> <property name="basepackage" value="${custom.logging.basepackage}" />
reference: autowiring in aspect
Comments
Post a Comment