AOP的原理是什么

這篇文章主要講解了“AOP的原理是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“AOP的原理是什么”吧!

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,寧武企業(yè)網(wǎng)站建設,寧武品牌網(wǎng)站建設,網(wǎng)站定制,寧武網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,寧武網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

AOP的原理
對哪些對象在什么位置攔截做什么 <=> <aop:before method="before" pointcut-ref="txPointcut" />
哪些對象
<!-- 定義切面,所有的service的所有方法 --> 
        <aop:pointcut id="txPointcut" expression="execution(* com.masterslave.service.*.*(..))" /> 
dataSourceAspect 是切面要攔截什么。aop:before就是在攔截對象的前面位置。method="before"就是使用切面中的方法處理攔截 
85 <aop:aspect ref="dataSourceAspect" order="-9999"> 
86 <aop:before method="before" pointcut-ref="txPointcut" /> 
87 </aop:aspect> 
如上是用配置文件配置的
還有方法是直接用注解方式
注解中也說明了,攔截范圍@Pointcut,在什么位置@Before,做什么@Aspect,具體攔截對象是誰JoinPoint
@Aspect
public class LoggingAspect {


// @Pointcut("execution(* com.samsung.sdsc.legal..*Impl.*(..)) || execution(* com.samsung.sdsc.legal..*Action.*(..))")
@Pointcut("execution(* com.samsung.sdsc.legal..*Impl.*(..))")
public void serviceMethod() {
}


@Before("serviceMethod()")
public void beforeLogging(JoinPoint thisJoinPoint) {
Class<? extends Object> clazz = thisJoinPoint.getTarget().getClass();
Logger logger = Logger.getLogger(clazz);
String methodName = thisJoinPoint.getSignature().getName();
Object[] arguments = thisJoinPoint.getArgs();


StringBuffer argBuf = new StringBuffer();
StringBuffer argValueBuf = new StringBuffer();
int i = 0;
for (Object argument : arguments) {
String argClassName = "";
if (null == argument) {
argClassName = "Null";
argument = "";
} else {
argClassName = argument.getClass().getSimpleName();
}


if (i > 0) {
argBuf.append(", ");
}
argBuf.append(argClassName + " arg" + ++i);
argValueBuf.append(".arg" + i + " : " + argument.toString() + "\n");


}


if (i == 0) {
argValueBuf.append("No arguments\n");
}


StringBuffer messageBuf = new StringBuffer();
messageBuf.append("before executing " + methodName + "("
+ argBuf.toString() + ") method");
messageBuf
.append("\n-------------------------------------------------------------------------------\n");
messageBuf.append(argValueBuf.toString());
messageBuf
.append("-------------------------------------------------------------------------------");
logger.info(messageBuf);


}
}

感謝各位的閱讀,以上就是“AOP的原理是什么”的內容了,經(jīng)過本文的學習后,相信大家對AOP的原理是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!

網(wǎng)站標題:AOP的原理是什么
文章來源:http://bm7419.com/article24/gejeje.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、品牌網(wǎng)站設計、網(wǎng)站設計公司、營銷型網(wǎng)站建設、定制網(wǎng)站、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營