Bootstrap

2022-4-24

springboot学习第一天:

  • 自定义banner
  • 配置文件,自定义属性注入@ConfigurationProperties @Value
  • 自定义注解

学习内容:

自定义banner

在classpath下新建banner.txt

  1. 配置文件使用spring.banner.location设置
  2. 配置文件使用spring.banner.image.location设置

支持txt、png、jpg、gif格式

配置文件,属性自动注入

@ConfigurationProperties
prefix属性配置前缀
需要配合@Component注解搭配使用(目的在于将当前类注入到spring容器中)

@Value(“${user.name}”)使用方式
不用提供set方法

配置文件优先级
classpath:./config/>classpath:./

环境区分
application-dev.yaml
application-test.yaml

使用spring.profiles.active=dev进行设置

自定义注解

新建:public @interface MyAnnotation

jdk自带4个元注解:
1、@Target(ElementType.FIELD):注解使用目标位置(字段)
2、@Retention(RetentionPolicy.RUNTIME):注解生命周期,什么时候生效(运行时期)
3、@Inherited:表明改注解支持继承特性
4、@Documented:支持文档注释

注解中的属性
String name() default ‘hehe’

Class[] mc() defalult {}

boolean proxyBeanMethods() default true;

;