一、参数配置化

配置文件在Java代码中,太分散,不方便维护与管理


有类似的场景,通过这种方式,将所有的参数交给配置文件统一配置。
二、yml配置文件



application.yml
spring:
# 数据库连接信息
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/tlias
username: root
password: yuejie2001
# 文件上传信息
servlet:
multipart:
max-file-size: 10MB
max-request-size: 100MB
#mybatis配置
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
#阿里云oss配置
aliyun:
oss:
endpoint: https://oss-cn-qingdao.aliyuncs.com
accessKeyId: LTAI5tNLsktD8CepFxhnY2KB
accessKeySecret: nNS3eINnnwSSbLOPboaCjSpJvkE763
bucketName: picgoi
三、@ConfigurationProperties



package com.itheima.utils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data //这个必须声明
@Component //将这个类的实例化对象交给ioc容器管理
@ConfigurationProperties(prefix = "aliyun.oss")
public class aliOSSProperties {
private String endpoint;
private String accessKeyId;
private String accessKeySecret;
private String bucketName;
}

四、@ConfigurationProperties与@Value的区别
