飙血推荐
  • HTML教程
  • MySQL教程
  • JavaScript基础教程
  • php入门教程
  • JavaScript正则表达式运用
  • Excel函数教程
  • UEditor使用文档
  • AngularJS教程
  • ThinkPHP5.0教程

Spring面向切面(AOP)声明方式的整理

时间:2021-12-14  作者:匿名  

使用aop

首先需要 配置 aop头部

<beans xmlns="http://域名/schema/beans"
       xmlns:xsi="http://域名/2001/XMLSchema-instance"
       xmlns:aop="http://域名/schema/aop"   ----
       xsi:schemaLocation="http://域名/schema/beans
           http://域名/schema/beans/spring-beans-域名
           http://域名/schema/aop http://域名/schema/aop/spring-aop-域名">           ----
</beans>

Spring提供了两种切面声明方式。

1.基于XML配置方式声明切面。

 

 

<bean id="orderservice" class="域名域名rServiceBean"/>
    <bean id="log" class="域名域名rint"/>

 

 

 

 

 

2.基于注解方式声明切面。

@Aspect
public class LogPrint {
@Pointcut("execution(* 域名ice..*.*(..))")
private void anyMethod() {}//声明一个切入点
@Before("anyMethod() && args(userName)")//定义前置通知
public void doAccessCheck(String userName) {
}
@AfterReturning(pointcut="anyMethod()",returning="revalue")//定义后置通知
public void doReturnCheck(String revalue) {
}
@AfterThrowing(pointcut="anyMethod()", throwing="ex")//定义例外通知
    public void doExceptionAction(Exception ex) {
}
@After("anyMethod()")//定义最终通知
public void doReleaseAction() {
}
@Around("anyMethod()")//环绕通知
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
return 域名eed();
}
}
标签:切面JAVA
湘ICP备14001474号-3  投诉建议:234161800@qq.com   部分内容来源于网络,如有侵权,请联系删除。