构建后端第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
最新文章
- Curling 2.0
- Tomcat中取消断点
- 本地wampserver如何配置伪静态
- 【OOAD】OOP的主要特征
- 尝试制作了一个Panorama
- display:-webkit-box
- jQuery_效果(隐藏和显示)
- 《零成本实现Web自动化测试--基于Selenium》第二章 Selenium简介和基础
- C++类的大小
- 工欲善其事必先利其器-Notepad++使用小记(Python)
- iOS 开发者旅途中的指南针 - LLDB 调试技术
- C# Main函数详解
- sublime 安装package control
- Oracle Advanced Pricing White Papers
- (1)编译安装lamp三部曲之apache-技术流ken
- 自己动手写处理器之第二阶段(1)——可编程逻辑器件与PLD电路设计流程
- [Docker]Docker拉取,上传镜像到Harbor仓库
- django-内网项目上线测试部署步骤
- 不固定个数组,进行一一对应的组合,js将多个数组实现排列组合
- 笔记二:常用的h5语义化标签