aop 註解方式

2021-07-12 04:29:36 字數 1826 閱讀 6253

直接 demo

1.介面

package com.bird.service;

public inte***ce personserver

2.實現類

package com.bird.service.impl;

import com.bird.service.personserver;

public class personservicebean implements personserver

@override

public void update(string name, integer id)

@override

public string getpersonname(integer id)

}

3.切點

package com.bird.service;

import org.aspectj.lang.proceedingjoinpoint;

import org.aspectj.lang.annotation.after;

import org.aspectj.lang.annotation.afterreturning;

import org.aspectj.lang.annotation.afterthrowing;

import org.aspectj.lang.annotation.around;

import org.aspectj.lang.annotation.aspect;

import org.aspectj.lang.annotation.before;

import org.aspectj.lang.annotation.pointcut;

/** * 切面

*/@aspect

public class myinterceptor // 定義乙個切入點

@before("anymethod() && args(name,id)")

public void doaccesscheck(string name, integer id)

@afterreturning("anymethod()")

public void doafter()

@after("anymethod()")

public void after()

@afterthrowing("anymethod()")

public void doafterthrow()

@around("anymethod()")

public object dobasicprofiling(proceedingjoinpoint pjp) throws throwable

}

4.spring 配置 bean

<?xml version="1.0" encoding="utf-8"?>

5.junit 測試

package junit.test;

import org.junit.test;

import com.bird.service.personserver;

public class springaoptest

}

6.結果

進入環繞通知

gaoming,1

前置通知

我是update()方法

退出方法

最終通知

後置通知

Spring之AOP註解方式

註解實現aop 1.啟用aspectj支援 2.在切面類加入 component aspect 3.配置切入點表示式 4.加入增強的方法,注意 環繞增強的方法中一定要加入proceedingjoinpoint引數 5.切面優先順序用切面類實現介面 implements ordered 或 order...

Spring以註解方式使用aop

7.spring以註解方式使用 xmlversion 1.0 encoding utf 8 beans xmlns xsi xmlns xmlns context xmlns aop xsi schemalocation spring beans 4.2.xsd spring context 4.2...

註解方式實現aop 快速入門

基於註解的aop開發步驟 建立目標介面和目標類 內部有切點 建立切面類 內部有增強方法 將目標類和切面類的物件建立權交給 spring 在切面類中使用註解配置織入關係 在配置檔案中開啟元件掃瞄和 aop 的自動 測試 建立目標介面和目標類 內部有切點 public inte ce targetint...