第一步:封装一个Component,并加上如下注解,指明prefix
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
@Component
@Data
public class SmsComponent {
private String host;
private String path;
private String appcode;
private String smsSignId;
private String templateId;
第二步:导入依赖,这样第三步写的时候会有提示。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
第三步:在application.yml中配置
spring:
cloud:
sms:
host: xxx
path: xxx
appcode: xxx
sms-sign-id: xxx
template-id: xxxx