Aspect J xml配置开发

此版本Aspect J 适用于开发 ,先参考上一篇关于Spring Aspect J的配置

工程结构:

StudentServiceI.java

package com.baidu.beans4;

public interface StudentServiceI {
	
	void delete();
	
	String add();

}

StudentServiceImpl.java

package com.baidu.beans4;

public class StudentServiceImpl implements StudentServiceI{

	
	public void delete() {
		// TODO Auto-generated method stub
		System.out.println("delete student...");
	}

	
	public String add() {
		// TODO Auto-generated method stub
		System.out.println("add student...");
		return "add";
	}

}

MyAspect.java

package com.baidu.beans4;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;


public class MyAspect {

	
	public void myBefore(JoinPoint joinPoint) {
		System.out.println("前置增强。。。"+joinPoint);
		
	}
	
	public void myAfterReturning(JoinPoint joinPoint,Object reval) {
		System.out.println("后置增强!!!,返回值"+reval);
		
	}
	
	public void myAround(ProceedingJoinPoint joinPoint) throws Throwable {
		System.out.println("1.环绕增强前");
		Object res = joinPoint.proceed();
		System.out.println("2.环绕增强后"+res);
	}
	
	public void myAfter() {
		System.out.println("最终通知。。。。");  
	}

}

beans4.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd">
	<!-- 开启AspectJ自动代理-->	
	<aop:aspectj-autoproxy/>
	
	<bean id="studentServiceImpl" class="com.baidu.beans4.StudentServiceImpl"></bean>
	<bean id="myAspect" class="com.baidu.beans4.MyAspect"></bean>
	
	<aop:config>
		<aop:aspect ref="myAspect">
			<aop:pointcut expression="execution(* com.baidu.beans4..*(..))" id="poni1"/>
			<aop:before method="myBefore" pointcut-ref="poni1"/>
			<aop:after-returning method="myAfterReturning" returning="reval" pointcut-ref="poni1"/>
			<aop:around method="myAround" pointcut-ref="poni1"/>
		</aop:aspect>
	</aop:config>
	
</beans>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值