JSP 中Spring组合注解与元注解实例详解摘要: 注解(Annotation),也叫元数据。一种代码级别的说明。它与类、接口、枚举是在同一个层次。它可以声明在包、类、字段、方法、局部变量、方法参数等的前面,用来对这些元素进行说明1. 可以注解到别
JSP 中Spring组合注解与元注解实例详解
摘要: 注解(Annotation),也叫元数据。一种代码级别的说明。它与类、接口、枚举是在同一个层次。它可以声明在包、类、字段、方法、局部变量、方法参数等的前面,用来对这些元素进行说明
1. 可以注解到别的注解上的注解称为元注解,被注解的注解称为组合注解,通过组合注解可以很好的简化好多重复性的注解操作
2. 示例组合注解
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@ComponentScan
public @interface GroupAnnotation {
String[] value() default {};
}
代码解释:组合@Configuration 与 @ComponentScan 元注解,并覆盖value参数
3. 编写普通Bean
@Servicepublic class DemoService
{
public void sys()
{ System.out.println("组合注解示例");
}
}
4. 使用组合注解的配置类
@GroupAnnotation("com.xuanwu.annotation")
public class DemoConfig {
}
5. 运行
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new
AnnotationConfigApplicationContext(DemoConfig.class);
DemoService demoService = context.getBean(DemoService.class);
demoService.sys();
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
沃梦达教程
本文标题为:JSP 中Spring组合注解与元注解实例详解
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
猜你喜欢
- Spring Security权限想要细化到按钮实现示例 2023-03-07
- 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
- JSP页面间传值问题实例简析 2023-08-03
- Java实现顺序表的操作详解 2023-05-19
- Java中的日期时间处理及格式化处理 2023-04-18
- SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
- JSP 制作验证码的实例详解 2023-07-30
- ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
- Springboot整合minio实现文件服务的教程详解 2022-12-03
- 深入了解Spring的事务传播机制 2023-06-02