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注解的程序元素

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

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

 

 

posted @ 2018-01-19 16:52  不归徒_bin  阅读(919)  评论(0编辑  收藏  举报