1. Springboot源码常用注解
注解分类:
- 元注解:可以注解到别的注解上的注解。
- 组合注解:被注解的注解我们就称之为组合注解。当多个注解被标注在同一个类上时,可以将这多个注解合并成一个注解。这个被合并的注解就是组合注解,如@SpringBootApplication
@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 {// SpringBootApplication是一个组合注解
@AliasFor(
annotation = EnableAutoConfiguration.class,
attribute = "exclude"
)
Class<?>[] exclude() default {};
@AliasFor(
annotation = EnableAutoConfiguration.class,
attribute = "excludeName"
)
1.1 @Value 【Spring 提供】
@Value
就相当于传统 xml 配置文件中的 value 字段。
<bean class="RequestTestRunnerService">
<property name ="APP_ENV" value="pre"></property>
</bean>
@Value取值来源:
- 字面量 @Value("值")
- 通过
${key}
方式从环境变量中获取值 - 通过
${key}
方式全局配置文件 appli