Dear all,I found a problem when I'm using Spring AOP in my project.
If Annotation is used to define my business service bean, I can not get the excepted result. The related Java codes and Spring configurations are shown as
follow:
1.My Spring Configuration aop configurations
2.My business service classCode:<context:annotation-config/> <aop:config> <aop:pointcut id="businessPoint" expression="execution(* com.jacky.menu.bus.impl.*.*(..))" /> <aop:advisor advice-ref="businessAdvisor" id="afterBusAdvisor" pointcut-ref="businessPoint"/> </aop:config> <bean id="businessAdvisor" class="com.jacky.menu.aop.BusinessAdvisor"></bean>
3.My after returning advise classCode:@Service public class MenuManagerImpl implements IMenuManager { @Autowired private IMenuDao menuDao; /* * (non Javadoc) * * @see com.jacky.menu.bus.IMenuManager#generateMenu() */ public Menu generateMenu(){ List<Menu> list = menuDao.getMenuList(); return this.generateTreeMenu(list); } }
If I define MenuManagerImpl.class as a spring bean by set a "@Service" Annotation, I can not get the output result of afterReturning method in the system console. But if I declare the MenuManagerImpl in the Spring configuration files like this:"Code:public class BusinessAdvisor implements AfterReturningAdvice { @Override public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { System.out.println("AOP business class after business method returning invoked!"); System.out.println("Class:" + target.getClass().getName()); System.out.println("Mehtod:" + method.getName()); } }", the excepted result of afterReturning method will be printed in the system console.Code:<bean id="menuManager" class="com.jacky.menu.bus.impl.MenuManagerImpl"></bean>
I dont know what is the reason, and how to make it work if I config my business service class with a "@Service" Annotation?


Reply With Quote
