IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> spring aop使用说明 -> 正文阅读

[游戏开发]spring aop使用说明


spring aop使用说明

?????????

?????????????????

????????????????????????????????????

相关注解

????????

@Aspect:声明一个切面

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})    //标注在类上
public @interface Aspect {
    String value() default "";
}

??????

@Before:前置通知,在方法调用前执行

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})   //标注在方法上
public @interface Before {
    String value();

    String argNames() default "";
}

?????????

@After:后置通知,在方法调用后执行

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})   //标注在方法上
public @interface After {
    String value();

    String argNames() default "";
}

????????

@AfterReturing:方法正常返回时调用

Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})     //标注在方法上
public @interface AfterReturning {
    String value() default "";

    String pointcut() default "";

    String returning() default "";

    String argNames() default "";
}

??????????

@AfterThrowing:方法抛出异常时调用

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})     //标注在方法上
public @interface AfterThrowing {
    String value() default "";

    String pointcut() default "";

    String throwing() default "";

    String argNames() default "";
}

????????

@Around:环绕通知,可实现前面通知功能,需触发方法执行

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Around {
    String value();

    String argNames() default "";
}

???????????

??????????????

????????????????????????????????????

相关类与接口

?????????

JoinPoint:连接点

public interface JoinPoint {
    String METHOD_EXECUTION = "method-execution";
    String METHOD_CALL = "method-call";
    String CONSTRUCTOR_EXECUTION = "constructor-execution";
    String CONSTRUCTOR_CALL = "constructor-call";
    String FIELD_GET = "field-get";
    String FIELD_SET = "field-set";
    String STATICINITIALIZATION = "staticinitialization";
    String PREINITIALIZATION = "preinitialization";
    String INITIALIZATION = "initialization";
    String EXCEPTION_HANDLER = "exception-handler";
    String SYNCHRONIZATION_LOCK = "lock";
    String SYNCHRONIZATION_UNLOCK = "unlock";
    String ADVICE_EXECUTION = "adviceexecution";

    String toString();
    String toShortString();
    String toLongString();

    Object getThis();   //获取当前对象
    Object getTarget(); //获取目标对象
    Object[] getArgs(); //获取参数体

    Signature getSignature();    //获取签名信息(可回去方法签名)

    SourceLocation getSourceLocation();

    String getKind();

    JoinPoint.StaticPart getStaticPart();

    public interface EnclosingStaticPart extends JoinPoint.StaticPart {
    }

    public interface StaticPart {

        int getId();
        String getKind();
        Signature getSignature();
        SourceLocation getSourceLocation();

        String toString();
        String toShortString();
        String toLongString();
    }
}

?????????

ProceedingJoinPoint:连接点,环绕通知使用

public interface ProceedingJoinPoint extends JoinPoint {
    void set$AroundClosure(AroundClosure var1);

    default void stack$AroundClosure(AroundClosure arc) {
        throw new UnsupportedOperationException();
    }

    Object proceed() throws Throwable;

    Object proceed(Object[] var1) throws Throwable;
}

?????????

Signature:方法签名接口

public interface Signature {

    String toString();
    String toShortString();
    String toLongString();

    String getName();
    int getModifiers();

    Class getDeclaringType();
    String getDeclaringTypeName();
}

?????????????

CodeSignature

public interface CodeSignature extends MemberSignature {

    Class[] getParameterTypes();   //获取参数类型
    String[] getParameterNames();  //获取参数名称

    Class[] getExceptionTypes();   //获取方法抛出的异常类型数组
}

??????????

MethodSignature

public interface MethodSignature extends CodeSignature {

    Class getReturnType();  //获取方法返回类型
    Method getMethod();     //获取切点方法
}

???????

Method

public final class Method extends Executable {
    private Class<?>            clazz;
    private int                 slot;

    private String              name;
    private Class<?>            returnType;
    private Class<?>[]          parameterTypes;
    private Class<?>[]          exceptionTypes;
    private int                 modifiers;

    private transient String              signature;
    private transient MethodRepository genericInfo;

    private byte[]              annotations;
    private byte[]              parameterAnnotations;
    private byte[]              annotationDefault;

    private Method              root;
    private volatile MethodAccessor methodAccessor;


    Method(Class<?> declaringClass,
           String name,
           Class<?>[] parameterTypes,
           Class<?> returnType,
           Class<?>[] checkedExceptions,
           int modifiers,
           int slot,
           String signature,
           byte[] annotations,
           byte[] parameterAnnotations,
           byte[] annotationDefault) {
    Method copy() {


    public Class<?> getDeclaringClass() {    //方法所在的类

    public String getName() {
    public int getModifiers() {
    public Object getDefaultValue() {

    public Class<?> getReturnType() {
    public Type getGenericReturnType() {
    public AnnotatedType getAnnotatedReturnType() {

    public int getParameterCount() {
    public Class<?>[] getParameterTypes() {
    public Type[] getGenericParameterTypes() {
    public TypeVariable<Method>[] getTypeParameters() {

    public Class<?>[] getExceptionTypes() {
    public Type[] getGenericExceptionTypes() {

    public Object invoke(Object obj, Object... args)
        throws IllegalAccessException, IllegalArgumentException,
           InvocationTargetException
    {

    public Annotation[] getDeclaredAnnotations()  {
    public Annotation[][] getParameterAnnotations() {
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {

    public boolean isBridge() {
    public boolean isVarArgs() {
    public boolean isSynthetic() {
    public boolean isDefault() {

    public boolean equals(Object obj) {
    public int hashCode() {
    public String toString() {
    public String toGenericString() {


    void specificToStringHeader(StringBuilder sb) {
    void specificToGenericStringHeader(StringBuilder sb) {
    void handleParameterNumberMismatch(int resultLength, int numParameters) {
    void setMethodAccessor(MethodAccessor accessor) {

    boolean hasGenericInformation() {

    Executable getRoot() {
    byte[] getAnnotationBytes() {
    MethodAccessor getMethodAccessor() {
    MethodRepository getGenericInfo() {

    private String getGenericSignature() {
    private GenericsFactory getFactory() {
    private MethodAccessor acquireMethodAccessor() {

?????????????

??????????????????

????????????????????????????????????

反射工具类

?????????

AopUtils

public abstract class AopUtils {
    public AopUtils() {
    }

    public static boolean isAopProxy(@Nullable Object object) {    //是否是aop代理(cglib代理或者jdk代理)
    public static boolean isJdkDynamicProxy(@Nullable Object object) {  //是否是jk代理
    public static boolean isCglibProxy(@Nullable Object object) {       //是否是cglib代理

    public static Class<?> getTargetClass(Object candidate) {   //获取目标对象类(被代理类)

    public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args) throws Throwable {
                         //触发方法调用

    public static Method selectInvocableMethod(Method method, @Nullable Class<?> targetType) {

    public static boolean isEqualsMethod(@Nullable Method method) {
    public static boolean isHashCodeMethod(@Nullable Method method) {
    public static boolean isToStringMethod(@Nullable Method method) {
    public static boolean isFinalizeMethod(@Nullable Method method) {

    public static Method getMostSpecificMethod(Method method, @Nullable Class<?> targetClass) {

    public static boolean canApply(Pointcut pc, Class<?> targetClass) {
    public static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasIntroductions) {

    public static boolean canApply(Advisor advisor, Class<?> targetClass) {
    public static boolean canApply(Advisor advisor, Class<?> targetClass, boolean hasIntroductions) {

    public static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz) {

????????????

ReflectionUtils

public abstract class ReflectionUtils {
    public static final ReflectionUtils.MethodFilter USER_DECLARED_METHODS = (method) -> {
        return !method.isBridge() && !method.isSynthetic() && method.getDeclaringClass() != Object.class;
    };
    public static final ReflectionUtils.FieldFilter COPYABLE_FIELDS = (field) -> {
        return !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers());
    };
    private static final String CGLIB_RENAMED_METHOD_PREFIX = "CGLIB$";
    private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
    private static final Method[] EMPTY_METHOD_ARRAY = new Method[0];
    private static final Field[] EMPTY_FIELD_ARRAY = new Field[0];
    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
    private static final Map<Class<?>, Method[]> declaredMethodsCache = new ConcurrentReferenceHashMap(256);
    private static final Map<Class<?>, Field[]> declaredFieldsCache = new ConcurrentReferenceHashMap(256);

    public ReflectionUtils() {
    }

    public static void handleReflectionException(Exception ex) {
    public static void handleInvocationTargetException(InvocationTargetException ex) {

    public static void rethrowRuntimeException(Throwable ex) {
    public static void rethrowException(Throwable ex) throws Exception {


    public static <T> Constructor<T> accessibleConstructor(Class<T> clazz, Class<?>... parameterTypes) throws NoSuchMethodException {

    public static void makeAccessible(Constructor<?> ctor) {


*********
method操作

    public static void makeAccessible(Method method) {

    public static Method findMethod(Class<?> clazz, String name) {
    public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes) {

    public static Object invokeMethod(Method method, @Nullable Object target) {
    public static Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args) {

    public static void doWithLocalMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc) {
    public static void doWithMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc) {
    public static void doWithMethods(Class<?> clazz, ReflectionUtils.MethodCallback mc, @Nullable ReflectionUtils.MethodFilter mf) {

    public static Method[] getDeclaredMethods(Class<?> clazz) {
    public static Method[] getAllDeclaredMethods(Class<?> leafClass) {
    public static Method[] getUniqueDeclaredMethods(Class<?> leafClass) {
    public static Method[] getUniqueDeclaredMethods(Class<?> leafClass, @Nullable ReflectionUtils.MethodFilter mf) {

    public static boolean isEqualsMethod(@Nullable Method method) {
    public static boolean isHashCodeMethod(@Nullable Method method) {
    public static boolean isToStringMethod(@Nullable Method method) {
    public static boolean isObjectMethod(@Nullable Method method) {
    public static boolean isCglibRenamedMethod(Method renamedMethod) {
    public static boolean declaresException(Method method, Class<?> exceptionType) {


    private static boolean hasSameParams(Method method, Class<?>[] paramTypes) {
    private static Method[] getDeclaredMethods(Class<?> clazz, boolean defensive) {
    private static List<Method> findConcreteMethodsOnInterfaces(Class<?> clazz) {


*********
field操作

    public static void makeAccessible(Field field) {

    public static Field findField(Class<?> clazz, String name) {
    public static Field findField(Class<?> clazz, @Nullable String name, @Nullable Class<?> type) {

    public static void setField(Field field, @Nullable Object target, @Nullable Object value) {
    public static Object getField(Field field, @Nullable Object target) {

    public static void doWithLocalFields(Class<?> clazz, ReflectionUtils.FieldCallback fc) {
    public static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc) {
    public static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc, @Nullable ReflectionUtils.FieldFilter ff) {

    public static boolean isPublicStaticFinal(Field field) {
    public static void shallowCopyFieldState(final Object src, final Object dest) {

    private static Field[] getDeclaredFields(Class<?> clazz) {


    public static void clearCache() {
        declaredMethodsCache.clear();
        declaredFieldsCache.clear();
    }


*********
内部接口:FieldFilter

    @FunctionalInterface
    public interface FieldFilter {
        boolean matches(Field field);

        default ReflectionUtils.FieldFilter and(ReflectionUtils.FieldFilter next) {
            Assert.notNull(next, "Next FieldFilter must not be null");
            return (field) -> {
                return this.matches(field) && next.matches(field);
            };
        }
    }


*********
内部接口:FieldCallback

    @FunctionalInterface
    public interface FieldCallback {
        void doWith(Field field) throws IllegalArgumentException, IllegalAccessException;
    }


*********
内部接口:MethodFilter

    @FunctionalInterface
    public interface MethodFilter {
        boolean matches(Method method);

        default ReflectionUtils.MethodFilter and(ReflectionUtils.MethodFilter next) {
            Assert.notNull(next, "Next MethodFilter must not be null");
            return (method) -> {
                return this.matches(method) && next.matches(method);
            };
        }
    }


*********
内部接口:MethodCallback

    @FunctionalInterface
    public interface MethodCallback {
        void doWith(Method method) throws IllegalArgumentException, IllegalAccessException;
    }
}

????????

??????????????????

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-04-23 11:07:26  更:2022-04-23 11:07:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年1日历 -2025/1/16 21:34:34-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码