Spring 源码注解

一.@Retention可以用来修饰注解,是注解的注解,称为元注解。
     Retention注解有一个属性value,是RetentionPolicy类型的,Enum RetentionPolicy是一个枚举类型,

注解按生命周期来划分可分为3类:

1、RetentionPolicy.SOURCE:注解只保留在源文件,当Java文件编译成class文件的时候,注解被遗弃;
2、RetentionPolicy.CLASS:注解被保留到class文件,但jvm加载class文件时候被遗弃,这是默认的生命周期;
3、RetentionPolicy.RUNTIME:注解不仅被保存到class文件中,jvm加载class文件之后,仍然存在;

这3个生命周期分别对应于:Java源文件(.java文件) ---> .class文件 ---> 内存中的字节码。

二。SpringMvc跨域支持

      从Spring MVC 4.2 开始增加支持跨域访问

1.在类或方法上增加@CrossOrigin注解

 

origins  : 允许可访问的域列表

  1. List of allowed origins, e.g. "http://domain1.com".   
  2. These values are placed in the Access-Control-Allow-Origin header of both the pre-flight response and the actual response. "*" means that all origins are allowed.   
  3.   
  4. If undefined, all origins are allowed.  

 maxAge:飞行前响应的缓存持续时间的最大年龄(以秒为单位)。

  1. The maximum age (in seconds) of the cache duration for pre-flight responses.   
  2. This property controls the value of the Access-Control-Max-Age header in the pre-flight response.   
  3. Setting this to a reasonable value can reduce the number of pre-flight request/response interactions required by the browser. A negative value means undefined.   
  4. If undefined, max age is set to 1800 seconds (i.e., 30 minutes).  

2.@Controller 和  @RestController的区别?
     官方文档:
    @RestController is a stereotype annotation that combines @ResponseBody and @Controller.
    意思是:
    @RestController注解相当于@ResponseBody + @Controller合在一起的作用。

3.用 @Deprecated注解的程序元素

    不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择。

    在使用不被赞成的程序元素或在不被赞成的代码中执行重写时,编译器会发出警告。

 

 

转载于:https://www.cnblogs.com/xwy6/p/8317816.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值