diff --git a/src/main/java/cn/zhangdeman/ICustomExceptionAnnotation.java b/src/main/java/cn/zhangdeman/ICustomExceptionAnnotation.java new file mode 100644 index 0000000..d8b1f95 --- /dev/null +++ b/src/main/java/cn/zhangdeman/ICustomExceptionAnnotation.java @@ -0,0 +1,9 @@ +package cn.zhangdeman; + +import java.util.Map; + +// 为了支持注解扫描, 自定义exception必须实现此注解 +public interface ICustomExceptionAnnotation { + // 获取错误码列表: code => message + public Map getCodeTable(); +} diff --git a/src/main/java/cn/zhangdeman/annotation/CustomExceptionAnnotation.java b/src/main/java/cn/zhangdeman/annotation/CustomExceptionAnnotation.java new file mode 100644 index 0000000..a31ebf0 --- /dev/null +++ b/src/main/java/cn/zhangdeman/annotation/CustomExceptionAnnotation.java @@ -0,0 +1,13 @@ +package cn.zhangdeman.annotation; + +import java.lang.annotation.*; + +// 自定义异常注解 +// 此注解会自动解析执行异常类, 将异常信息注册到 `HashMapCache` 中 +@Retention(RetentionPolicy.RUNTIME) // 定带有注解类型的注解要保留多长时间。它需要一个RetentionPolicy参数,可以是SOURCE、CLASS或 之一RUNTIME。例如,@Retention(RetentionPolicy.RUNTIME)意味着注解应该由 JVM 保留,以便可以在运行时反射性地使用。 +@Target(ElementType.TYPE) // 注解会施加在自定义异常类之上 +@Inherited // @Inherited注解表示注解类型被自动继承。如果一个类被标注了@Inherited,那么它的子类也会继承该注解。 +public @interface CustomExceptionAnnotation { + String exceptionPackageList() default ""; // 哪些包下定义了异常类, 多个包路径用 , 分隔 + String exceptionClassList() default ""; // 异常类路径, 多个类用 , 分隔 +}