spring-aop-annotation

1。假設你已經配好依賴注入那一塊。此時的bean.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:context="http://www.springframework.org/schema/context"
? ? ?xsi:schemaLocation="http://www.springframework.org/schema/beans
? ? ? ? ?http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
? ? ? ? ?http://www.springframework.org/schema/context
? ? ? ? ?http://www.springframework.org/schema/context/spring-context-3.0.xsd">
? ?<!-- 打開Spring的Annotation支持 -->
? ?<context:annotation-config/>
? ?<!-- 設定Spring 去哪些包中找Annotation -->
? ?<context:component-scan base-package="org.zttc.itat.spring"/>
? ? ? ? ? ?
</beans>
?
2.加上aop的schema????
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop ? ?
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
3.?打開基于Annotation的AOP?
<aop:aspectj-autoproxy/>
最后的bean.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"
? ? ?xmlns:context="http://www.springframework.org/schema/context"
? ? ?xsi:schemaLocation="http://www.springframework.org/schema/beans
? ? ? ? ?http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
? ? ? ? ?http://www.springframework.org/schema/context
? ? ? ? ?http://www.springframework.org/schema/context/spring-context-3.0.xsd
? ? ? ? ?http://www.springframework.org/schema/aop
? ? ? ? ?http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
? ?<!-- 打開Spring的Annotation支持 -->
? ?<context:annotation-config/>
? ?<!-- 設定Spring 去哪些包中找Annotation -->
? ?<context:component-scan base-package="org.zttc.itat.spring"/>
? ?<!-- 打開基于Annotation的AOP -->
? ?<aop:aspectj-autoproxy/>
? ?
</beans>
4.創建一個aop的關注點。 叫LogAspect.java.
package org.zttc.itat.spring.proxy;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
?
@Component("logAspect")//讓這個切面類被Spring所管理
@Aspect//申明這個類是一個切面類
public class LogAspect {
/**execution說明我要在那些方法上使用該方法
?* execution(* org.zttc.itat.spring.dao.*.add*(..))
?* 第一個*表示任意返回值
?* 第二個*表示 org.zttc.itat.spring.dao包中的所有類
?* 第三個*表示以add開頭的所有方法
?* (..)表示任意參數
?*/
@Before("execution(* org.zttc.itat.spring.dao.*.add*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.delete*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.update*(..))")
public void logStart(JoinPoint jp) {
//得到執行的對象
System.out.println(jp.getTarget());
//得到執行的方法
System.out.println(jp.getSignature().getName());
Logger.info("加入日志");
}
/**
?* 函數調用完成之后執行
?* @param jp
?*/
@After("execution(* org.zttc.itat.spring.dao.*.add*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.delete*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.update*(..))")
public void logEnd(JoinPoint jp) {
Logger.info("方法調用結束加入日志");
}
/**
?* 函數調用中執行
?* @param pjp
?* @throws Throwable
?*/
@Around("execution(* org.zttc.itat.spring.dao.*.add*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.delete*(..))||" +
"execution(* org.zttc.itat.spring.dao.*.update*(..))")
public void logAround(ProceedingJoinPoint pjp) throws Throwable {
Logger.info("開始在Around中加入日志");
pjp.proceed();//執行程序
Logger.info("結束Around");
}
}
4.1 導入aopalliance.jar ? aspectjrt.jar ?aspectjweaver.jar三個包,因為spring是使用Aspect來實現AOP
總結:spring的AOP還是很簡單的,前面配置好的依賴注入的例子根本不用動,我在這個給dao織入了方法,但是這只是這里單方面的知道,從被織的對象來說,它根本不知道你是不是給自己加入了方法。

轉載于:https://www.cnblogs.com/yujianjingjing/archive/2013/03/10/2953072.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/376825.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/376825.shtml
英文地址,請注明出處:http://en.pswp.cn/news/376825.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

c++實現簡單線程池代碼

目錄完整代碼TaskPool.cppTaskPool.hmain.cpp完整代碼 TaskPool.cpp // // Created by LENOVO on 2021/10/25. //#include "TaskPool.h" #include <functional>std::mutex printMutex;TaskPool::TaskPool() : m_bRunning(false) {}TaskPool::~TaskPool() {re…

Android靜態圖片人臉識別的完整demo(附完整源碼)

Demo功能&#xff1a;利用android自帶的人臉識別進行識別&#xff0c;標記出眼睛和人臉位置。點擊按鍵后進行人臉識別&#xff0c;完畢后顯示到imageview上。 第一部分&#xff1a;布局文件activity_main.xml [html] view plaincopyprint?<RelativeLayout xmlns:android&qu…

圖論:最短路徑搜索--Dijkstra算法(c代碼實現)

最近因為辭職&#xff0c;有不少閑功夫&#xff0c;重溫下數據結構&#xff0c;順便練練手。今天說說最短路徑搜索算法中的Dijkstra原理和實現。 一&#xff1a;簡介 這個算法用于解決圖中單源最短路徑問題。所謂單源節點是指給定源節點&#xff0c;求圖中其它節點到此源節點的…

C++多線程快速入門(五)簡單線程池設計

目錄設計思路主線程運行邏輯task以及taskpool設計詳細流程講解完整代碼打印結果往期回顧設計思路 線程池實際上就是一組線程&#xff0c;當我們需要異步執行一些任務時&#xff0c;經常要通過OS頻繁創建和銷毀線程&#xff0c;不如直接創建一組在程序生命周期內不會退出的線程…

C--函數

函數:具有特定功能的代碼段,分為庫函數,自定義函數. 函數定義: 函數返回值類型 函數名(形式參數列表) { 代碼段; return 返回值; } 注意:每個函數返回值最多只有一個.return是一個函數結束的標志. 形式參數(形參):函數定義時使用的虛擬參數名,用以接收函數調用是傳遞過來的實際…

公式系統 - TradeBlazer公式基礎 - Bar數據

Bar數據 在介紹Bar數據之前&#xff0c;首先&#xff0c;我們需要討論一下TradeBlazer公式的計算方法&#xff0c;針對上面介紹的各種公式類型&#xff0c;包含公式應用&#xff0c;在公式進行計算時&#xff0c;都是建立在基本數據源(Bar數據)之上&#xff0c;我們這里所謂的B…

C++網絡編程快速入門(一):TCP網絡通信基本流程以及基礎函數使用

目錄流程概述服務器端代碼實現客戶端代碼實現函數和結構講解sockaddr_in和sockaddrsocket &#xff1a; 創建一個socket連接bind &#xff1a;綁定地址以及端口號問題流程概述 客戶端與服務器之間的網絡通信基本原理如下所示&#xff0c;復雜一點的架構可能會添加消息中間件。…

php 字符串處理

addcslashes — 為字符串里面的部分字符添加反斜線轉義字符addslashes — 用指定的方式對字符串里面的字符進行轉義bin2hex — 將二進制數據轉換成十六進制表示chop — rtrim() 的別名函數chr — 返回一個字符的ASCII碼chunk_split — 按一定的字符長度將字符串分割成小塊conve…

使用前端框架Foundation 4來幫助簡化響應式設計開發

日期&#xff1a;2013-3-12 來源&#xff1a;GBin1.com Foundation是一套使用廣泛的前端開發套件&#xff0c;可以幫助你快速的網站。最近ZURB發布了一個新版本的Foundation 4前端框架&#xff0c;能夠有效的幫助你快速的開發響應式的網站。 和另外一個套知名的前端框架BootSt…

C++網絡編程快速入門(二):Linux下使用select演示簡單服務端程序

目錄select參數解釋select使用規范select使用缺點基本流程實例代碼通信效果演示往期文章select參數解釋 extern int select (int __nfds, fd_set *__restrict __readfds,fd_set *__restrict __writefds,fd_set *__restrict __exceptfds,struct timeval *__restrict __timeout)…

Android轉載一:Android文件命名規范

REF&#xff1a;http://blog.csdn.net/gulianchao/article/details/23391651 (一) Layout命名 1&#xff0e;contentview命名&#xff1a;activity_功能模塊.xml 例如&#xff1a;activity_main.xml、activity_more.xml 2&#xff0e;Dialog命名&#xff1a;dialog_描述.xml …

[轉]XBRL應用軟件分類

1) 分類標準編輯軟件(Taxonomy editor)&#xff1a; 分類標準是XBRL技術的應用基礎&#xff0c;每一個采用XBRL技術的國家都必須先按各國的GAAP制訂XBRL分類標準&#xff0c;上市公司才能據以編制實例文件。由于一套XBRL 2.0或2.1版分類標準必須包含至少一份XML Schema文…

C++網絡編程快速入門(三):阻塞與非阻塞式調用網絡通信函數

目錄阻塞與非阻塞定義send與recvconnect一些問題為什么要將監聽socket設置為非阻塞阻塞與非阻塞定義 阻塞模式指的是當前某個函數執行效果未達預期&#xff0c;該函數會阻塞當前的執行線程&#xff0c;程序執行流在超時時間到達或者執行成功后恢復原有流程。非阻塞模式相反&am…

css3實現頭像旋轉360度

css樣式: .div a img{ width: 88px; height: 88px; border-radius: 88px; transition: all 1.2s ease-out 0s;}.div a img:hover{ -webkit-transform:rotate(360deg); -moz-transform:rotate(360deg); -o-transform:rotate(360deg); -ms-transform:rotate(360deg); transform:r…

POJ 2488 深搜

POJ 2488 深搜 要求字典序的順序。 1 #include <iostream>2 #include <stdio.h>3 #include <string.h>4 using namespace std;5 int n,m,cnt;6 bool success;7 bool sign[30][30];8 int step[30][2];9 int dir[8][2]{ 10 -2,-1,-2,1, 11 …

socket 端口和地址復用

https://blog.csdn.net/weibo1230123/article/details/79978745 https://blog.csdn.net/weixin_42157432/article/details/115560824 在linux socket網絡編程中&#xff0c;大規模并發TCP或UDP連接時&#xff0c;經常會用到端口復用&#xff1a; int opt 1; if (setsockopt…

MyEclipse老是彈出problem occurred窗口

有的時候是因為jsp頁面中的java腳本有誤&#xff0c;比如說<% String name"";>就會出現錯誤&#xff0c;因為結束標簽少了一個百分號&#xff05;。轉載于:https://www.cnblogs.com/passer1991/archive/2013/03/15/2961624.html

C++網絡編程快速入門(四):EPOLL模型使用

目錄基本使用方法step1:創建epollfdstep2:將fd綁定到epollfdstep3:調用epoll_wait檢測事件epoll_wait與poll、select區別所在水平觸發與邊緣觸發基本使用方法 step1:創建epollfd 創建一個epollfd&#xff0c;若epoll_create調用成功&#xff0c;則返回一個非負值的epollfd&am…

Mysql中代替like模糊查詢的一種方法

使用Mysql的函數instr,可代替傳統的like方式查詢,并且速度更快。 instr函數&#xff0c;第一個參數是字段&#xff0c;第二個參數是要查詢的串&#xff0c;返回串的位置&#xff0c;第一個是1&#xff0c;如果沒找到就是0. 例如&#xff1a; select username from prefix_user …

兩種大小端判斷的方式

網絡通信是按照字節流進行數據交換的&#xff0c;主機根據不同的CPU型號可能是大段存儲&#xff0c;也可能是小端存儲。而網絡字節序在TCP/IP協議中已經規定好了&#xff0c;采用大端的排序方式。 所以網絡通信中一般將需要傳輸的整數型值轉換成網絡字節序。 從本機字節序轉換成…