日期:2014-05-17 浏览次数:20801 次
In this tutorial, we show you how to convert last Spring AOP + AspectJ annotation into XML based configuration.
For those don’t like annotation or using JDK 1.4, you can use AspectJ in XML based instead.
Review last customerBo interface again, with few methods, later you will learn how to intercept it via AspectJ in XML file.
package com.mkyong.customer.bo; public interface CustomerBo { void addCustomer(); String addCustomerReturnValue(); void addCustomerThrowException() throws Exception; void addCustomerAround(String name); }
AspectJ @Before example.
package com.mkyong.aspect; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class LoggingAspect { @Before("execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..))") public void logBefore(JoinPoint joinPoint) { //... } }
Equivalent functionality in XML, with <aop:before>.
<!-- Aspect --> <bean id="logAspect" class="com.mkyong.aspect.LoggingAspect" /> <