当前位置 : 主页 > 编程语言 > c++ >

AOP的几个增强类型使用

来源:互联网 收集:自由互联 发布时间:2021-06-30
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
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
@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();
	}
}
网友评论