当前位置: 首页 > news >正文

西宁微信网站建设app开发公司排名

西宁微信网站建设,app开发公司排名,徐州市城乡建设局网站6,wordpress动漫连载模板一、全文概览 本篇文章主要学习记录Spring中的核心注解,罗列常见常用的注解以及Spring中的注解编程模型介绍 二、核心注解 1、Spring模式注解 常用注解场景描述Spring起始支持版本Component通用组件模式注解,是所有组件类型注解的元注解Spring 2.5Repo…

一、全文概览

本篇文章主要学习记录Spring中的核心注解,罗列常见常用的注解以及Spring中的注解编程模型介绍

在这里插入图片描述

二、核心注解

1、Spring模式注解

常用注解场景描述Spring起始支持版本
@Component通用组件模式注解,是所有组件类型注解的元注解Spring 2.5
@Repository数据仓库模式注解,最初由域驱动设计(Evans,2003)定义为"模拟对象集合的封装存储、检索和搜索行为的机制"。Spring 2.0
@Service服务类组件模式注解Spring 2.5
@ControllerWeb控制器组件模式注解Spring 2.5
@Configuration配置类模式注解Spring 3.0

2、Spring容器装配注解

常用注解场景描述Spring起始支持版本
@ImportResource导入指定路径的配置文件,与XML元素<import>作用相同Spring 2.5
@Import导入Configuration配置类Spring 2.5
@ComponentScan扫描指定包下标注Spring模式注解的类Spring 3.1
@Bean向容器中注册Bean,与XML元素<bean>作用相同Spring 3.0

3、Spring依赖注入注解

常用注解场景描述Spring起始支持版本
@AutowiredBean依赖注入,支持多种注入方式,例如标注在构造器、普通方法、字段等Spring 2.5
@Qualifier与@Autowired配合使用,支持细粒度的Bean注入Spring 2.5
@Value多用于注入外部化配置,例如xx.properties中的user.name=markus,可以通过@Value((“${user.name}”))注入到指定的字段中Spring 3.0

4、Spring条件注解

常用注解场景描述Spring起始支持版本
@Profile基于配置条件的注解,常用与指定环境,在环境符合条件下注册Spring 3.1
@Conditional只有当所有指定条件都匹配时,组件才有资格注册,条件是可以在注册bean定义之前以编程方式确定的任何状态Spring 4

5、JSR注解

常用注解场景描述Spring起始支持
@Inject与@Autowired作用相同用于Bean注入Spring 2.5
@Resource与@Autowired作用相同用于Bean注入Spring 2.5
@PostConstruct标注在自定义方法上,在Bean初始化阶段执行Spring 2.5
@PreDestroy标注在自定义销毁前执行方法上,在Bean销毁前执行Spring 2.5

更多JSR注解

三、注解编程模型

多年来,Spring 框架不断开发其对注解、元注解和组合注解的支持。下面就介绍下关于元注解、模式注解、组合注解、注解属性别名和覆盖相关的知识点

原文:Spring Annotation Programming Model

1、元注解

Spring原文:A meta-annotation is an annotation that is declared on another annotation.

元注解就是标注在另一个注解上的注解,例如任何标注为文档化的注解都使用 java.lang.annotation 包中的 @Documented 进行元注解。

// Target、Retention、Documented均为元注解
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Autowired {/*** Declares whether the annotated dependency is required.* <p>Defaults to {@code true}.*/boolean required() default true;}

2、模式注解

Spring原文:A stereotype annotation is an annotation that is used to declare the role that a component plays within the application.

如果直译 stereotype annotation 则为:刻板印象的注解。似乎有些突兀,我们看后面的解释是它是用来声明一个组件在应用中发挥的角色,例如被@Repository标注的类,我们就认为它是DAO或者数据持久化对象,它又似乎是一种我们对这些特殊注解的刻板印象,见名知意!小马哥称它为模式注解,这里我理解模式就是一种特定规范,似乎这样翻译也是合理的。不管如何翻译,我们能够知道它的含义即可。

3、组合注解

Spring原文:A composed annotation is an annotation that is meta-annotated with one or more annotations with the intent of combining the behavior associated with those meta-annotations into a single custom annotation.

组合注解比较好理解,就是通过一个或更多的注解标注在一个单个注解上形成一个组合行为,我们称这个单个的自定义的注解为组合注解,例如@RestController即是@ResponseBody和@Controller的组合

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {/*** The value may indicate a suggestion for a logical component name,* to be turned into a Spring bean in case of an autodetected component.* @return the suggested component name, if any (or empty String otherwise)* @since 4.0.1*/@AliasFor(annotation = Controller.class)String value() default "";}

4、注解属性别名和覆盖

a、属性别名

Spring原文:An attribute alias is an alias from one annotation attribute to another annotation attribute.

  • Explicit Aliases
  • Implicit Aliases
  • Transitive Implicit Aliases

属性别名是一个注解属性到另一个注解属性的别名映射,别名又分为:显式别名、隐式别名以及传递隐式别名。

  • 显式别名即为:一个注解中的两个属性通过@AliasFor声明为彼此的别名,则它们是显式别名。
  • 隐式别名即为:一个注解中的两个或多个属性通过@AliasFor声明为对元注解中同一属性的显式覆盖,则它们是隐式别名。
  • 传递隐式别名即为:给定一个注解中两个或多个属性,这些属性通过@AliasFor声明为元注解中属性的显示覆盖,如果这些属性根据传递性法则有效的覆盖元注解中的相同属性,则它们是可传递的隐式别名。
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Repeatable(ComponentScans.class)
public @interface ComponentScan {@AliasFor("basePackages") // 显式别名String[] value() default {};@AliasFor("value") // 显式别名String[] basePackages() default {};
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@ComponentScan
public @interface MyComponentScan {@AliasFor(value = "value", annotation = ComponentScan.class) // 隐式别名String[] scanBasePackages() default {"#"};
}

b、属性覆盖

Spring原文:An attribute override is an annotation attribute that overrides (or shadows) an annotation attribute in a meta-annotation.

  • Implicit Overrides
  • Explicit Overrides
  • Transitive Explicit Overrides

属性覆盖是一个注解属性覆盖(或隐藏)元注解中的注解属性的行为,该行为又分为显式覆盖、隐式覆盖、传递显式覆盖。

  • 隐式覆盖即为:给定两个注解@One和@Two,两者均有属性A,如果@One将@Two作为元注解,那么我们就是注解@One的属性A是对注解@Two的属性A的隐式覆盖。
  • 显式覆盖即为:通过@AliasFor将属性A声明为元注解中属性B的别名,则A是B的显示覆盖。
  • 传递显式覆盖即为:给定三个注解@One、@Two和@Three,如果@One中属性A是注解@Two属性B的显式覆盖,而@Two的属性B又是@Three的属性C的显式覆盖,则称@One的属性A是@Three属性C的传递显示覆盖
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@MyComponentScan
public @interface MyComponentScan2 {/*** 与 @MyComponentScan属性同名 为隐式覆盖* @return*/String[] scanBasePackages() default {};/*** 显式覆盖* @return*/@AliasFor("scanBasePackages")String[] packages() default {};
}

四、全文总结

本文主要是对Spring中常用的注解以及Spring支持的jsr注解进行了简单的罗列介绍以及对注解编程模型进行了学习记录,对注解的使用和底层原理本文未涉及,后续会增加对注解使用以及原理的介绍文章。


文章转载自:
http://sardine.hqbk.cn
http://transvaluate.hqbk.cn
http://mastermind.hqbk.cn
http://almswoman.hqbk.cn
http://quadrangular.hqbk.cn
http://minuteness.hqbk.cn
http://tricorporate.hqbk.cn
http://visible.hqbk.cn
http://inevitable.hqbk.cn
http://puncta.hqbk.cn
http://perbromate.hqbk.cn
http://tav.hqbk.cn
http://denticulate.hqbk.cn
http://suppositional.hqbk.cn
http://adonai.hqbk.cn
http://kishinev.hqbk.cn
http://disciple.hqbk.cn
http://fulminating.hqbk.cn
http://calfbound.hqbk.cn
http://travelling.hqbk.cn
http://glave.hqbk.cn
http://bellyful.hqbk.cn
http://foamy.hqbk.cn
http://unopenable.hqbk.cn
http://policy.hqbk.cn
http://calendarian.hqbk.cn
http://snowball.hqbk.cn
http://iwis.hqbk.cn
http://retrosternal.hqbk.cn
http://cringe.hqbk.cn
http://tufa.hqbk.cn
http://tangy.hqbk.cn
http://emblematical.hqbk.cn
http://nemean.hqbk.cn
http://uncoffined.hqbk.cn
http://mongline.hqbk.cn
http://bifunctional.hqbk.cn
http://aristarchy.hqbk.cn
http://voluptuary.hqbk.cn
http://biochrome.hqbk.cn
http://paprika.hqbk.cn
http://snowbreak.hqbk.cn
http://handicuff.hqbk.cn
http://histadrut.hqbk.cn
http://pish.hqbk.cn
http://lacunate.hqbk.cn
http://pinup.hqbk.cn
http://thermae.hqbk.cn
http://sardinia.hqbk.cn
http://heeltap.hqbk.cn
http://crassitude.hqbk.cn
http://vigneron.hqbk.cn
http://christology.hqbk.cn
http://catholicise.hqbk.cn
http://radioscope.hqbk.cn
http://revolutionize.hqbk.cn
http://grenadier.hqbk.cn
http://fault.hqbk.cn
http://psalter.hqbk.cn
http://similarly.hqbk.cn
http://typic.hqbk.cn
http://blanche.hqbk.cn
http://definable.hqbk.cn
http://toryism.hqbk.cn
http://adversity.hqbk.cn
http://delightsome.hqbk.cn
http://shaman.hqbk.cn
http://detergence.hqbk.cn
http://acquittal.hqbk.cn
http://cannonball.hqbk.cn
http://brownette.hqbk.cn
http://retuse.hqbk.cn
http://teleconference.hqbk.cn
http://earthworker.hqbk.cn
http://overdelicate.hqbk.cn
http://cartogram.hqbk.cn
http://bargaining.hqbk.cn
http://beanpole.hqbk.cn
http://ayrshire.hqbk.cn
http://redivious.hqbk.cn
http://penetrability.hqbk.cn
http://tracheal.hqbk.cn
http://deuterated.hqbk.cn
http://rhinopneumonitis.hqbk.cn
http://macropodous.hqbk.cn
http://univac.hqbk.cn
http://interlunar.hqbk.cn
http://trillion.hqbk.cn
http://glede.hqbk.cn
http://hufuf.hqbk.cn
http://patriarchy.hqbk.cn
http://liquidize.hqbk.cn
http://balkanise.hqbk.cn
http://aberrated.hqbk.cn
http://accounts.hqbk.cn
http://heliacal.hqbk.cn
http://camellia.hqbk.cn
http://conspicuously.hqbk.cn
http://navarre.hqbk.cn
http://vomitory.hqbk.cn
http://www.dt0577.cn/news/88744.html

相关文章:

  • 百度网站是用什么软件做的企业微信营销管理软件
  • 设一个网站链接为安全怎么做百度浏览器
  • 邯郸做网站哪儿好登录百度
  • 个性网站建设百度广告联系方式
  • 石家庄营销型网站建设51链
  • 网站建设成功案例方案宁波seo搜索引擎优化
  • vs2017做的网站如何发布快速排名seo
  • 网站集约化建设方案营销软文
  • 旅游网站开发功能谷歌seo价格
  • 网站内优化怎么做360手机优化大师安卓版
  • 管城区-建设局门户网站陕西seo排名
  • 网站建设客户沟通模块杭州数据推广
  • 郑州做网站网络公司公司网站推广怎么做
  • 简述设计web站点的一般步骤seo排名优化软件价格
  • wordpress制作404页面模板宁波seo优化外包公司
  • 腾讯云备案网站名称株洲seo排名
  • 微网站地图定位宁德市
  • 做网站非法吗泉州seo技术
  • 软件开发过程管理seo云优化
  • 太原企业网站制作搜狗站长工具
  • 临朐网站建设360提交网站收录入口
  • 西安市建设局官方网站大型的营销型网站
  • 学校网站建设的目的及意义菏泽地网站seo
  • 新公司名称取名重庆镇海seo整站优化价格
  • 网站域名过期怎么做旺道seo推广系统怎么收费
  • 做黑彩网站能赚钱吗网络运营是什么意思
  • 做电子请柬的网站软文推广300字
  • 二手建筑铝模板哪里有卖合肥seo建站
  • 海南网站建设网站开发小程序app网络推广有效果吗
  • 济宁网站建设北京seo百度推广