aopdemo.java package org.jxnd.aop;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.springframework.stereotype.Component;@Component@Aspectpublic c
package org.jxnd.aop; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Component @Aspect public class aopdemo { private static final String execution="execution(* org.jxnd.dao.*.*(..))"; @Before(value=execution) public void before(){ System.out.println("ǰǿ"); } @AfterThrowing(value=execution) public void Around(){ System.out.println("쳣"); } }IUdao.java
package org.jxnd.dao; public interface IUdao { void add ()throws Exception; void delete(); }Udao.java
package org.jxnd.dao; import org.springframework.stereotype.Component; @Component public class Udao implements IUdao { @Override public void add() throws Exception { System.out.println("----"); throw new Exception(); } @Override public void delete() { System.out.println("--ɾ-"); } }Test.java
package org.jxnd.test; import org.jxnd.dao.IUdao; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void main(String[] args) throws Exception { ApplicationContext context=new ClassPathXmlApplicationContext("spring_application.xml"); IUdao dao=context.getBean(IUdao.class); dao.add(); //dao.delete(); } }