1. 在yml中填写自定义配置
ly:
sms:
accessKeyId: # 短信配置
accessKeySecret:
signName: xx商城 # 签名名称
verifyCodeTemplate: SMS_156565156 # 模板名称
2. 写对应配置类
@Data
@ConfigurationProperties(prefix = "ly.sms")
public class SmsProperties {
private String accessKeyId;
private String accessKeySecret;
private String signName;
private String verifyCodeTemplate;
}
3. 在使用的类中启用配置类,并注入
@Component
@EnableConfigurationProperties(SmsProperties.class)
public class SmsUtils {
@Autowired
private SmsProperties prop;
public void test(){
prop.getAccessKeyId();
}
}