构建后端第3篇之---springb @Alias注解使用
write by 张艳涛 in 202210210,after today i will write aritles by english,because english is so diffent from chiness that i can't
understand english in java,spring doc notice ,so i begin to use english for a lifelong time. atthought is hard for me ,but i am a man would like learn little by little , yes is the only way to learn language by use it in common daily time
Tody I would lile recode usage of spring annotion @Aliasfor
Capture One
ToIntroduce @Aliasfor , you master kown the @SpringBootApplication ,it uses start Main Class, then show the context
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication { /**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
@AliasFor(annotation = EnableAutoConfiguration.class)
Class<?>[] exclude() default {}; /**
* Exclude specific auto-configuration class names such that they will never be
* applied.
* @return the class names to exclude
* @since 1.3.0
*/
@AliasFor(annotation = EnableAutoConfiguration.class)
String[] excludeName() default {}; /**
* Base packages to scan for annotated components. Use {@link #scanBasePackageClasses}
* for a type-safe alternative to String-based package names.
* @return base packages to scan
* @since 1.3.0
*/
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {}; /**
* Type-safe alternative to {@link #scanBasePackages} for specifying the packages to
* scan for annotated components. The package of each class specified will be scanned.
* <p>
* Consider creating a special no-op marker class or interface in each package that
* serves no purpose other than being referenced by this attribute.
* @return base packages to scan
* @since 1.3.0
*/
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {}; }
and with
@SpringBootApplication(scanBasePackages ={ "com.zyt" } )//这个是rouyi的方案
public class ZytAuthApplication {
public static void main(String[] args) {
SpringApplication.run(ZytAuthApplication.class, args);
System.out.println("(◠‿◠)ノ゙ 授权认证中心启动成功 ლ(´ڡ`ლ)゙ \n" );
}
}
you can know the attibute (scanBasePackages ={ "com.zyt" } ) is for
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {};
then the SpringBootApplication Annotation attibute scanBasePackages ={ "com.zyt" } , so we can undestand
@AliasFor isfor give scanBasePackages ={ "com.zyt" } to ComponentScan.class ,
ComponentScan overrite its attibute with {"com.zyt"}
In One World like meta-annotation get attibute value from Top Annotation 's attibute
this is call Explicit alias for attribute in meta-annotation:
Capture Two
Explicit aliases within an annotation:
public @interface ContextConfiguration {
@AliasFor("locations")
String[] value() default {};
@AliasFor("value")
String[] locations() default {};
// ...
}
for more
Capture Three
Example: Implicit Aliases within an Annotation
@ContextConfiguration
public @interface MyTestConfig { @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] value() default {}; @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] groovyScripts() default {}; @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] xmlFiles() default {};
}
@MyTestConfig
public @interface GroovyOrXmlTestConfig { @AliasFor(annotation = MyTestConfig.class, attribute = "groovyScripts")
String[] groovy() default {}; @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] xml() default {};
}
for more
构建后端第3篇之---springb @Alias注解使用的更多相关文章
- 构建后端第2篇之---springb @ComponentScan注解使用
张艳涛写于2021-2-8日 构建后端项目的时候遇到一个问题,在zyt-auth项目的依赖定义了@Component类,这个类在项目启动的时候提示没有找到bean Field tokenService ...
- 构建后端第6篇之---java 多态的本质 父类引用 指向子类实现
张艳涛写于2021-2-20 今天来个破例了,不用英文写了,今天在家里电脑写的工具不行,简单的说 主题是:java多态的原理与实现 结论是:java的多态 Father father= new Son ...
- 构建后端第5篇之---Idea 查看继承 实现关系图
first question: how to show a class children class : move mousrmark to class name , Ctrl + H how t ...
- 构建后端第4篇之---spring 源码阅读构建环境
解决 IDEA 创建 Gradle 项目没有src目录问题 in new model named zyt-study root dir there are a build.gradle plug ...
- 构建后端第1篇之---springcloud项目依赖分析
张艳涛写于2021-2-2日 springcloud是springboot工程+cloud依赖,从这个角度来分析,使用springcloud实际上就是添加springcloud的某个以来比如eurek ...
- JSON工具类的构建(后端版本)
前言 在前后端交互的选择上,之前一直采用的是模板引擎(因为我只负责后端). 而这次的一个算是作业吧,前后端都是我,所以就研究了一下JSON交互在java web的应用(主要是前端). 优缺点 前后端耦 ...
- 高效使用Java构建工具,Maven篇|云效工程师指北
大家好,我是胡晓宇,目前在云效主要负责Flow流水线编排.任务调度与执行引擎相关的工作. 作为一个有多年Java开发测试工具链开发经验的CRUD专家,使用过所有主流的Java构建工具,对于如何高效使用 ...
- NodeJS+Express下构建后端MVC文件结构
关于MVC的结构大体上有两种方式,其一按照层级进行文件夹分类,其二是按照业务进行文件夹分类.关于这个demo相关的业务简单,所以暂采用第一种的方式,当然实际当中很恨复杂的项目可以采用两种方式相结合的方 ...
- gulp前端自动化构建工具新手入门篇
很久没有更新博文了. 经过了一次年前吐血的赶项目,终于在年后回血了.趁着有空,新学到了一个前端自动化构建工具-gulp. 现在我们通过这3个问题来学习一下: 1.什么是gulp? 2.为什么要用gul ...
随机推荐
- Qt实现网络聊天室(客户端,服务端)
1. 效果演示 客户端 服务器 连接成功之后 2. 预备知识 如果不知道网络编程的可以去看我的上一篇文章C++网络编程 在Qt中,实现网络编程的方式比用C++或C实现要方便简单许多,因为Qt已经替我们 ...
- JAVA设计模式(6:单例模式详解)
单例模式作为一种创建型模式,在日常开发中用处极广,我们先来看一一段代码: // 构造函数 protected Calendar(TimeZone var1, Locale var2) { this.l ...
- 复习Spring第二课--AOP原理及其实现方式
AOP原理: AOP,面向方面的编程,使用AOP,你可以将处理方面(Aspect)的代码注入主程序,通常主程序的主要目的并不在于处理这些aspect.AOP可以防止代码混乱.AOP的应用范围包括:持久 ...
- R-常见错误
错误一:选择了未定义的列(Undefined columns are selected) 改正方法:把目标列转换成因子类型(as.factor) 使用代码如下: 或者: 错误二:太多(36119)的重 ...
- 为什么catch了异常,但事务还是回滚了?
前几天我发了这篇文章<我来出个题:这个事务会不会回滚?>得到了很多不错的反馈,也有不少读者通过微信.群或者邮件的方式,给了我一些关于test4的回复.其中还有直接发给我测试案例,来证明我的 ...
- uniapp 打包IOS 更新AppStore版本
Hello 你好,我是大粽子. 最近随着新版本UI的发布APP也随之更新,随之而来的也就是IOS程序提审步骤,这次我详细的截图了每一个步骤,如果你正好也需要那么跟着我的节奏一步步来肯定是没问题的. 提 ...
- Pytest学习笔记9-失败重跑
前言 在进行自动化测试的过程中,我们一定会有这样的需求:希望失败的用例可以自动重跑 在pytest中,提供了pytest-rerunfailures插件可以实现自动重跑的效果 插件安装 pip命令安装 ...
- hive学习笔记之十:用户自定义聚合函数(UDAF)
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是<hive学习笔记>的第十 ...
- 从零开始给女朋友讲计算机 1 - 从比特、字节、补码到 ASCII、GB2312、Unicode
起因 在代码 review 的过程中,总是发现有人在数据类型转换(reinterpret_cast).大小端的问题(什么情况下需要考虑大小端,什么情况下不需要考虑)上犯错误,究其原因是没有彻彻底底地搞 ...
- 重学 Spring Boot
什么是Spring Boot Spring Boot 是 Spring 开源组织下的一个子项目,也是 Spring 组件一站式解决方案,主要是为了简化使用 Spring 框架的难度和简化 Spring ...