java之什么是注解(Annotations)

历史

注解是JDK1.5引入的一个特性:

JDK 1.5 has a new interesting feature called annotations. It allows you to specify xdoclet like tags right in the Java language just as you can with C#. These tags are typesafe and access to them is available at compile time, load-time, and run-time. See JSR-175 for more detail. JBossAOP since beta2 does support JDK1.5 annotations

我们到JSR-175那里再看一下介绍: 

A metadata facility for the JavaTM Programming Language would allow classes, interfaces, fields, and methods to be marked as having particular attributes.

这一年是2004年。 

举例说明,在子类的重写方法前使用@Override注解:

class Cat extends Animal {
    @Override
    public String getFirstName() {
        
    }
}

这样,如果父类更改了getFirstName方法,子类的编译就会报错,这样我们第一时间就会发现,而不是运行报错后再排查。

Spring注解

而Spring Framework 1.0是在2003-2004年间,即处在JDK 1.4到JDK 1.5的过渡时代。其实从Spring Framework 1.2就开始兼容JDK 1.5注解方面的特性,Spring Framework 3.0开始大量出现注解的使用,如条件注解等。

Spring核心注解场景分类

Spring注解场景说明起始版本
@Repository数据仓储模式注解2.0
@Component通用组件模式注解2.5
@Serive服务模式注解2.5
@ControllerWeb控制器模式注解2.5
@Configuration配置类模式注解3.0

Spring Boot注解

注解场景说明起始版本
@SpringBootConfigurationSpring Boot配置类1.4.0
@SpringBootApplicationSpring Boot应用引导注解1.2.0
@EnableAutoConfigurationSpring Boot激活自动转配1.0.0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值