mercredi 11 mars 2015

Spring register advisor

I am so confused that how Spring register the advisor when startup.


my situation is define Advisor that extends from AspectJExpressionPointcutAdvisor like below



public class TestAdvisor extends AspectJExpressionPointcutAdvisor {

}


I don't mark this class with @Component, then I create another class that used to create TestAdvisor in some condition



@Component
public AdvisorContext implements InitializeBean {
@Autowired private ApplicationContext ctx;
@Override
public void afterPropertiesSet() throws Exception {
if(conditionMatch()){
AutowireCapableBeanFactory bf = ctx.getAutowireCapableBeanFactory();
TestAdvisor advisor = bf.createBean(TestAdvisor.class);
advisor.setExpression("expression");
advisor.setAdvice(ctx.getBean(TestAdvice.class);
}
}
}


I am sure this afterPropertiesSet() has been called, but the advisor didn't take effect.


if I mark TestAdvisor with @Component, then the advice works.


Are there any other extra steps I have to do in order to add advisor?


thanks


Aucun commentaire:

Enregistrer un commentaire