SpringBoot 注解相关工具类(AnnotationUtils、AnnotatedElementUtils...)

本文主要是介绍SpringBoot 注解相关工具类(AnnotationUtils、AnnotatedElementUtils...),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Scope("singleton")
@Component
// 表明注解会被子类继承
@Inherited
public @interface SingletonComponent {@AliasFor(annotation = Component.class, attribute = "value")String value() default "";String name() default "";
}
@SingletonComponent(value = "parent/controller", name = "parent")
public class ParentController {}@SingletonComponent(value = "child/controller")
public class ChildController extends ParentController {}
public class AnswerApp {public static void main(String[] args) throws Exception {// 父类拥有注解 SingletonComponent, 子类没有System.out.println("ParentController getAnnotation @SingletonComponent: " + AnnotationUtils.getAnnotation(ParentController.class, SingletonComponent.class));System.out.println("ChildController getAnnotation @SingletonComponent: " + AnnotationUtils.getAnnotation(ChildController.class, SingletonComponent.class));System.out.println();System.out.println("ParentController findAnnotation @SingletonComponent: " + AnnotationUtils.findAnnotation(ParentController.class, SingletonComponent.class));System.out.println("ParentController findAnnotation @SingletonComponent: " + AnnotationUtils.findAnnotation(ChildController.class, SingletonComponent.class));System.out.println();System.out.println("ParentController isAnnotated @SingletonComponent: " + AnnotatedElementUtils.isAnnotated(ParentController.class, SingletonComponent.class));System.out.println("ParentController getMergedAnnotation @SingletonComponent: " + AnnotatedElementUtils.getMergedAnnotation(ParentController.class, SingletonComponent.class));System.out.println("ChildController isAnnotated @SingletonComponent: " + AnnotatedElementUtils.isAnnotated(ChildController.class, SingletonComponent.class));System.out.println("ChildController getMergedAnnotation @SingletonComponent: " + AnnotatedElementUtils.getMergedAnnotation(ChildController.class, SingletonComponent.class));System.out.println();System.out.println("ParentController hasAnnotation @SingletonComponent: " + AnnotatedElementUtils.hasAnnotation(ParentController.class, SingletonComponent.class));System.out.println("ParentController findMergedAnnotation @SingletonComponent: " + AnnotatedElementUtils.findMergedAnnotation(ParentController.class, SingletonComponent.class));System.out.println("ChildController hasAnnotation @SingletonComponent: " + AnnotatedElementUtils.hasAnnotation(ChildController.class, SingletonComponent.class));System.out.println("ChildController findMergedAnnotation @SingletonComponent: " + AnnotatedElementUtils.findMergedAnnotation(ChildController.class, SingletonComponent.class));}
}
ParentController getAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=parent, value=parent/controller)
ChildController getAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=, value=child/controller)ParentController findAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=parent, value=parent/controller)
ParentController findAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=, value=child/controller)ParentController isAnnotated @SingletonComponent: true
ParentController getMergedAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=parent, value=parent/controller)
ChildController isAnnotated @SingletonComponent: true
ChildController getMergedAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=, value=child/controller)ParentController hasAnnotation @SingletonComponent: true
ParentController findMergedAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=parent, value=parent/controller)
ChildController hasAnnotation @SingletonComponent: true
ChildController findMergedAnnotation @SingletonComponent: @com.jaemon.aal.define.SingletonComponent(name=, value=child/controller)

这篇关于SpringBoot 注解相关工具类(AnnotationUtils、AnnotatedElementUtils...)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1005421

相关文章

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

Java中的数组与集合基本用法详解

《Java中的数组与集合基本用法详解》本文介绍了Java数组和集合框架的基础知识,数组部分涵盖了一维、二维及多维数组的声明、初始化、访问与遍历方法,以及Arrays类的常用操作,对Java数组与集合相... 目录一、Java数组基础1.1 数组结构概述1.2 一维数组1.2.1 声明与初始化1.2.2 访问

Javaee多线程之进程和线程之间的区别和联系(最新整理)

《Javaee多线程之进程和线程之间的区别和联系(最新整理)》进程是资源分配单位,线程是调度执行单位,共享资源更高效,创建线程五种方式:继承Thread、Runnable接口、匿名类、lambda,r... 目录进程和线程进程线程进程和线程的区别创建线程的五种写法继承Thread,重写run实现Runnab

Java 方法重载Overload常见误区及注意事项

《Java方法重载Overload常见误区及注意事项》Java方法重载允许同一类中同名方法通过参数类型、数量、顺序差异实现功能扩展,提升代码灵活性,核心条件为参数列表不同,不涉及返回类型、访问修饰符... 目录Java 方法重载(Overload)详解一、方法重载的核心条件二、构成方法重载的具体情况三、不构

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

SpringBoot线程池配置使用示例详解

《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

基于Python实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

一文详解SpringBoot中控制器的动态注册与卸载

《一文详解SpringBoot中控制器的动态注册与卸载》在项目开发中,通过动态注册和卸载控制器功能,可以根据业务场景和项目需要实现功能的动态增加、删除,提高系统的灵活性和可扩展性,下面我们就来看看Sp... 目录项目结构1. 创建 Spring Boot 启动类2. 创建一个测试控制器3. 创建动态控制器注

Java操作Word文档的全面指南

《Java操作Word文档的全面指南》在Java开发中,操作Word文档是常见的业务需求,广泛应用于合同生成、报表输出、通知发布、法律文书生成、病历模板填写等场景,本文将全面介绍Java操作Word文... 目录简介段落页头与页脚页码表格图片批注文本框目录图表简介Word编程最重要的类是org.apach