JSP custom annotations and operation logs, jsp custom annotation logs
JSP custom annotation and operation Logging
Spring configuration file
<aop:aspectj-autoproxy />
Log interceptor
Package com. vem. interceptor; import org. aspectj. lang. proceedingJoinPoint; import org. aspectj. lang. annotation. around; import org. aspectj. lang. annotation. aspect; import org. aspectj. lang. annotation. pointcut; import org. aspectj. lang. reflect. methodSignature; import org. springframework. stereotype. component; import com. vem. entity. bussAnnotation; @ Aspect @ Component public class LogInterceptor {@ Pointcut ("execution (* com. vem. service .. *. *(..)) ") public void aApplogic () {}/ *** the surround notification is used to intercept specified content and record user operations */@ Around (value =" aApplogic () & @ annotation (annotation) & args (object ,..) ", argNames =" annotation, object ") public void interceptorApplogic (ProceedingJoinPoint joinPoint, BussAnnotation annotation, Object object) throws Throwable {System. out. println ("module name moduleName:" + annotation. moduleName (); System. out. println ("Operation name option:" + annotation. option (); String methodName = joinPoint. getSignature (). getName (); System. out. println ("method name methodName:" + methodName); MethodSignature methodSignature = (MethodSignature) joinPoint. getSignature (); String [] strings = methodSignature. getParameterNames (); joinPoint. proceed (); Object [] arguments = joinPoint. getArgs (); // obtain the parameter list if (arguments. length <= 0) {System. out. println (methodName + "method has no parameter");} else {for (int I = 0; I <arguments. length; I ++) {System. out. println (strings [I] + ":" + arguments [I] + ":");}}}}
Custom Annotation
@ Retention (RetentionPolicy. RUNTIME) @ Target ({ElementType. METHOD}) @ brief ented public @ interface BussAnnotation {// Module name String moduleName () default ""; // operation content String option () default "";}
Interface implementation
Written in service
@ BussAnnotation (moduleName = "Personnel Management", option = "Add User") public void testDemo1 (PageData pd) throws Exception {}
Junit testing class
package com.vem.entity;import javax.annotation.Resource;import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.vem.service.data.DemoService;import com.vem.util.PageData; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( {"classpath:spring/ApplicationContext.xml" })public class AopTest { @Resource(name = "demoService") public DemoService demoService; @Test public void testAopAddUser1(){ PageData pd = new PageData(); pd.put("name", "zhangzexing"); pd.put("age", "21"); pd.put("passward", "123456"); try { demoService.testDemo2(pd); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!