في الآونة الأخيرة ، يحتاج المشروع إلى إنشاء وظيفة تسجيل ، والتي أستخدمها طريقة التعليق التوضيحي لـ Spring AOP للتنفيذ.
إنشاء التعليقات التوضيحية السجل
package com.wyj.annotation ؛ import java.lang.annotation.documented ؛ import java.lang.annotation.ElementType ؛ import java.lang.annotation.retention ؛ import java.lang.annotation.rentepolicy ؛ * date: 26 أغسطس ، 2016 في الساعة 8:25:35 مساءً */@target (elementType.method) reation (attreentionpolicy.runtime) documentedpublic interface syslog {string action () الافتراضي "؛ // action}إنشاء فئة إعلام الوجه
سجل اسم الطريقة والمعلمات والوقت الذي يقضيه في العملية ، باستخدام الإخطارات المحيطة
package com.wyj.aspect ؛ import java.lang.reflect.method ؛ import org.aspectj.lang.proceditingjoinpoint ؛ import org.aspectj.lang.Antation.around ؛ import org.aspectj.lang.annotation.Aspect ؛ org.aspectj.lang.reflect.methodSignature ؛ استيراد org.springframework.beans.factory.annotation.autowired ؛ استيراد org.springframework.stereotype.component com.wyj.service.syslogservice ؛/** * تسجيل قسم القسم * * * * Author: Wangyuanjun * date: 26 أغسطس ، 2016 في 10:28:57 PM */ @joffe @componentpublic class syslogaspect {autowired syslogservice syslogservice ؛ / ** * point of intrading */ @pointcut (" @enrotation (com.wyj.annotation.syslog)") public void pointcut () {}/ ** * prounding cointive * * param joinpoint * return * @throws remable */ around ( System.CurrentTimeMillis () ؛ // تنفيذ نتيجة كائن طريقة الهدف = JoinPoint.proceed () ؛ // وقت التنفيذ (milliseconds) وقت طويل = System.CurrentTimeMillis () - Begintime ؛ // حفظ السجل SaveSyslog (JoinPoint ، الوقت) ؛ نتيجة العودة } / ** * احفظ السجل * * param joinpoint * param time * / private void savesyslog (proseingJoinPoint JoinPoint ، time long) {methodsignature signature = (methodsignature) coinpoint.getSignature () ؛ طريقة طريقة = signature.getMethod () ؛ syslogentity syslogentity = syslogentity () جديد ؛ syslog syslog = method.getAnnotation (syslog.class) ؛ if (syslog! = null) {// الوصف على syslogentity.setOperation (syslog.action ()) ؛ } // الحصول على الهدف className = joinpoint.getTarget (). getClass (). getName () ؛ // احصل على اسم الأسلوب سلسلة methodName = signature.getName () ؛ syslogentity.setMethod (className + "." + methodName + "()") ؛ // كائن المعلمة المطلوب [] args = JoinPoint.getArgs () ؛ if (args! = null && args.length! = 0 && args [0]! = null) {syslogentity.setParams (args [0] .toString ()) ؛ } syslogentity.Settime (time) ؛ // حفظ سجل النظام syslogservice.save (syslogentity) ؛ }}مسح وبدء شرح AOP
تطبيق شرح السجل
تأثير
طريقة تكوين التعليق التوضيحية لـ AOP الخاصة بـ SPRING AOP لتنفيذ إدارة السجل هي كل المحتوى الذي أشاركه معك. آمل أن تتمكن من إعطائك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.