Spring AOP implements business log records

Source: Internet
Author: User
Tags aop

1. User management business logic Interface (Usermanagerapplogic.java) Java code package com.iteye.applogic;   Public interface Usermanagerapplogic {public void AddUser (String name); }

2.&NBSP User management business logic implementation Class (Usermanagerapplogicimpl.java) Java code    package  com.iteye.applogic.impl;      import org.springframework.stereotype.component;       import com.iteye.applogic.usermanagerapplogic;   import  com.iteye.annotation.bussannotation;   @Component ("Usermanager")     Public class  UserManagerApplogicImpl implements UserManagerApplogic {            @BussAnnotation (modulename= "People Management", option= "Add user")        public  void adduser (string name)  {            System.out.println ("add a user! name is  "+name";       }  }    

3. Business Annotation Class (Busannotation.java) Java code package com.iteye.annotation;   Import Java.lang.annotation.ElementType;   Import java.lang.annotation.Retention;   Import Java.lang.annotation.RetentionPolicy;      Import Java.lang.annotation.Target;       @Retention (Retentionpolicy.runtime) @Target ({Elementtype.method}) public @interface bussannotation {//module name       String ModuleName ();   Action content String option (); }

(1) The Retentionpolicy (retention policy) is an enum type with a total of three values, Source,class and RUNTIME respectively.

Source represents the annotation type of information will only remain in the program source code, if the source code is compiled, the annotation data will disappear, and will not be kept in the compiled. class file.

class represents that the annotation type of information is retained in the source code of the program, but it is also kept in the compiled. class file, and does not load this information into the virtual machine (JVM) at the time of execution. . Note that when you do not set a annotation type of retention value, the system default is class.

runtime represents the retention of information in the source code, compiled. class file, which loads the information into the JVM when it is executed.

(2) ElementType

The ElementType inside the @target is used to specify which elements the annotation type can be used on.

Type is the type that can be used on class,interface,enum and annotation types.

FIELD (properties)

Method (Methods)

PARAMETER (Parameters)

Constructor (constructors)

local_variable (local variable)

Annotation_type

PACKAGE (Package)

(3) @Documented

The purpose of @Documented is to allow this type of annotation information to be displayed on the JAVAAPI documentation; If not added, the information generated by this type will not be found when using Javadoc to generate API documents.

(4) @Inherited

If you need to inherit the annotation data to the subclass, you will use the @inherited annotation type.

4. Slice class (Loginterceptor.java) Java code package COM.ITEYE.AOP;   Import Org.aspectj.lang.ProceedingJoinPoint;   Import Org.aspectj.lang.annotation.Around;   Import Org.aspectj.lang.annotation.Aspect; Import Org.aspectj.lang.annotation.Pointcut;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.